我已经在c#中创建了示例ftp服务器,并且想将文件从android发送到它。我在网络编程领域还很新,所以有人可以向我展示最简单的方法吗? 我已经尝试过像一些网络指南中那样做,但是对我来说这是行不通的。我一直在使用FTP appache liblary,但是在创建FTPClint对象之后:
FTPClient ftp = new FTPClient();
我无法连接到服务器:
ftp.connect("192.xxx.x.x",21);
e.printStackTrace():
2019-02-14 20:25:36.904 16949-16968/studio.janek.ftpclienttest
> I/OpenGLRenderer: Initialized EGL, version 1.4 2019-02-14 20:25:36.904
> 16949-16968/studio.janek.ftpclienttest D/OpenGLRenderer: Swap behavior
> 1 2019-02-14 20:25:36.944 16949-16949/studio.janek.ftpclienttest
> W/art: Before Android 4.1, method int
> android.support.v7.widget.DropDownListView.lookForSelectablePosition(int,
> boolean) would have incorrectly overridden the package-private method
> in android.widget.ListView 2019-02-14 20:25:44.919
> 16949-16949/studio.janek.ftpclienttest W/System.err:
> android.os.NetworkOnMainThreadException 2019-02-14 20:25:44.920
> 16949-16949/studio.janek.ftpclienttest W/System.err: at
> android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303)
> 2019-02-14 20:25:44.920 16949-16949/studio.janek.ftpclienttest
> W/System.err: at
> java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:333)
> 2019-02-14 20:25:44.920 16949-16949/studio.janek.ftpclienttest
> W/System.err: at
> java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
> 2019-02-14 20:25:44.920 16949-16949/studio.janek.ftpclienttest
> W/System.err: at
> java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
> 2019-02-14 20:25:44.920 16949-16949/studio.janek.ftpclienttest
> W/System.err: at
> java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356) 2019-02-14
> 20:25:44.920 16949-16949/studio.janek.ftpclienttest W/System.err:
> at java.net.Socket.connect(Socket.java:605) 2019-02-14 20:25:44.920
> 16949-16949/studio.janek.ftpclienttest W/System.err: at
> org.apache.commons.net.SocketClient._connect(SocketClient.java:243)
> 2019-02-14 20:25:44.920 16949-16949/studio.janek.ftpclienttest
> W/System.err: at
> org.apache.commons.net.SocketClient.connect(SocketClient.java:202)
> 2019-02-14 20:25:44.920 16949-16949/studio.janek.ftpclienttest
> W/System.err: at
> studio.janek.ftpclienttest.FTPCLientCode.SendFile(MainActivity.java:117)
> 2019-02-14 20:25:44.920 16949-16949/studio.janek.ftpclienttest
> W/System.err: at
> studio.janek.ftpclienttest.MainActivity.send_Click(MainActivity.java:53)
> 2019-02-14 20:25:44.920 16949-16949/studio.janek.ftpclienttest
> W/System.err: at java.lang.reflect.Method.invoke(Native Method)
> 2019-02-14 20:25:44.920 16949-16949/studio.janek.ftpclienttest
> W/System.err: at
> android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:385)
> 2019-02-14 20:25:44.920 16949-16949/studio.janek.ftpclienttest
> W/System.err: at android.view.View.performClick(View.java:5647)
> 2019-02-14 20:25:44.920 16949-16949/studio.janek.ftpclienttest
> W/System.err: at
> android.view.View$PerformClick.run(View.java:22465) 2019-02-14
> 20:25:44.920 16949-16949/studio.janek.ftpclienttest W/System.err:
> at android.os.Handler.handleCallback(Handler.java:754) 2019-02-14
> 20:25:44.920 16949-16949/studio.janek.ftpclienttest W/System.err:
> at android.os.Handler.dispatchMessage(Handler.java:95) 2019-02-14
> 20:25:44.920 16949-16949/studio.janek.ftpclienttest W/System.err:
> at android.os.Looper.loop(Looper.java:163) 2019-02-14 20:25:44.920
> 16949-16949/studio.janek.ftpclienttest W/System.err: at
> android.app.ActivityThread.main(ActivityThread.java:6238) 2019-02-14
> 20:25:44.921 16949-16949/studio.janek.ftpclienttest W/System.err:
> at java.lang.reflect.Method.invoke(Native Method) 2019-02-14
> 20:25:44.921 16949-16949/studio.janek.ftpclienttest W/System.err:
> at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
> 2019-02-14 20:25:44.921 16949-16949/studio.janek.ftpclienttest
> W/System.err: at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)