-1

I'm using this Code:

    ftpClient.connect(InetAddress.getByName(10.0.0.100));
ftpClient.login(user, password);
ftpClient.changeWorkingDirectory(serverRoad);
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
BufferedInputStream buffIn=null;
buffIn=new BufferedInputStream(new FileInputStream(file));
ftpClient.enterLocalPassiveMode();
ftpClient.storeFile("test.txt", buffIn);
buffIn.close();
ftpClient.logout();
ftpClient.disconnect();

And my project crashes in this line

ftpClient.connect(InetAddress.getByName(server));

So the server ip has to be false, I used the ip from the pc where the server is running. IP: 10.0.0.100 What is wrong with this Ip?

Btw I'm using apache commons

Then it throws me this:

      D: [NET] android_getaddrinfofornet+,hn 16(0x6674703a2f2f31),sn(),hints(known),family 0,flags 4
D: [NET] android_getaddrinfofornet-, err=8
W: android.os.NetworkOnMainThreadException
W:     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1155)
W:     at java.net.InetAddress.lookupHostByName(InetAddress.java:418)
W:     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:252)
W:     at java.net.InetAddress.getByName(InetAddress.java:305)
W:     at com.example.mathias.newproject.MainActivity.connnectingwithFTP(MainActivity.java:89)
W:     at com.example.mathias.newproject.MainActivity$2.onClick(MainActivity.java:52)
W:     at android.view.View.performClick(View.java:4785)
W:     at android.view.View$PerformClick.run(View.java:19858)
W:     at android.os.Handler.handleCallback(Handler.java:739)
W:     at android.os.Handler.dispatchMessage(Handler.java:95)
W:     at android.os.Looper.loop(Looper.java:155)
W:     at android.app.ActivityThread.main(ActivityThread.java:5696)
W:     at java.lang.reflect.Method.invoke(Native Method)
W:     at java.lang.reflect.Method.invoke(Method.java:372)
W:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
W:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mathias.newproject" >

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" >


        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >


            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
Ribisl
  • 149
  • 1
  • 10
  • Are you have internet permissions in your manifest? please share logcat – Santiago Oct 27 '15 at 12:10
  • Share the logs as well as the snippet where you have declared the variable 'server' – darthvading Oct 27 '15 at 12:17
  • added logcat and manifest @Santiago – Ribisl Oct 27 '15 at 18:04
  • @darthvading the varible 'server' is declared as string in "10.0.0.100" – Ribisl Oct 27 '15 at 18:06
  • @Ribisl the EACCES means that is most likely an internal error, and you didnt even tried to check the given IP. Check the answers for additional permissions that may be needed. – Bonatti Oct 27 '15 at 18:59
  • Try to access to your server from another PC, if this can access rebuild your project – Santiago Oct 27 '15 at 19:33
  • The IP should be right, if I use it on my PC, it works great. Will I need a special IP like ftp://10.0.0.100 (didn't work anyway) @Bonatti – Ribisl Oct 27 '15 at 19:33
  • @Ribisl No, you will not need any special IP. As I stated, the `EACCES` kind of errors are errors that b lock code execution, because a necessary permission was not given. `INTERNET`, `ACCESS_NETWORK_STATE` and `ACCESS_WIFI_STATE` might all be needed from the code shown. Also, check my answer, your manifest is wrong. – Bonatti Oct 28 '15 at 10:22

2 Answers2

1

Remove the uses-permission tags from application and move them to manifest

check here how a manifest must be written:

<manifest>

    <uses-permission />
    <permission />
    <permission-tree />
    <permission-group />
    <instrumentation />
    <uses-sdk />
    <uses-configuration />  
    <uses-feature />  
    <supports-screens />  
    <compatible-screens />  
    <supports-gl-texture />  

    <application>

            <activity>
            <intent-filter>
                <action />
                <category />
                <data />
            </intent-filter>
            <meta-data />
        </activity>

        <activity-alias>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </activity-alias>

        <service>
            <intent-filter> . . . </intent-filter>
            <meta-data/>
        </service>

        <receiver>
            <intent-filter> . . . </intent-filter>
            <meta-data />
        </receiver>

        <provider>
            <grant-uri-permission />
            <meta-data />
            <path-permission />
        </provider>

        <uses-library />

    </application>

</manifest>
Bonatti
  • 2,778
  • 5
  • 23
  • 42
  • worked but not completely, I have new logcat failure – Ribisl Oct 28 '15 at 16:17
  • You have several "wrong" things in the code, now, the new error is: `NetworkOnMainThreadException`, because you made `Network` related operations `On` the `Main` `Thread` and thus had an `Exception` thrown... if you google those terms, you will find [AsyncTask](http://developer.android.com/reference/android/os/AsyncTask.html), and then move on to the next issue. But google them first, or even use the Stack Overflow search... finally, if an answer helped you fix the issue, click the `v` symbol, near the arrows on the left, to help others find how to fix their issues – Bonatti Oct 28 '15 at 17:21
0

You may have missed this permission inside your AndroidManifest.xml.

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
vguzzi
  • 2,420
  • 2
  • 15
  • 19