Android FTP库

Dar*_*g8r 52 java ftp android

我正在寻找一个适用于android的java库,可以从FTP服务器下载和恢复文件.有谁知道这样的图书馆.我发现了很多客户端应用程序,但没有独立的库.

jfa*_*ell 81

尝试使用apache commons ftp

FTPClient ftpClient = new FTPClient();
ftpClient.connect(InetAddress.getByName(server));
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();
Run Code Online (Sandbox Code Playgroud)

  • 非常非常重要 - 活动模式不适用于您的Android设备.您必须进入被动模式.所以在连接和登录之间放这个:ftpClient.enterLocalPassiveMode(); (9认同)
  • 对于今后看这些人的人来说,Apache Commons Net正在为我工​​作.在build.gradle(Module:app)依赖中使用`implementation'monsons-net:commons-net:3.6'`. (8认同)
  • @Reno我很肯定你可以在你的项目中包含jar,它会毫无问题地运行.让它在几个应用程序中工作,它很好用. (6认同)