尝试使用ftp中的ftp4j从FTP下载文件后出现以下错误。
W/System.err: it.sauronsoftware.ftp4j.FTPException [code=426, message= Data connection error.]
12-16 11:29:30.496 22976-23595/ W/System.err: at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3484)
12-16 11:29:30.496 22976-23595/ W/System.err: at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3276)
12-16 11:29:30.496 22976-23595/ W/System.err: at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3181)
12-16 11:29:30.496 22976-23595/ W/System.err: at .MainActivity$FTPDownload.doInBackground(MainActivity.java:248)
12-16 11:29:30.496 22976-23595/ W/System.err: at .MainActivity$FTPDownload.doInBackground(MainActivity.java:234)
12-16 11:29:30.496 22976-23595/ W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:292)
12-16 11:29:30.496 22976-23595/ W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
12-16 11:29:30.496 22976-23595/ W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
12-16 11:29:30.496 22976-23595/ W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
12-16 11:29:30.496 22976-23595/ W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
12-16 11:29:30.496 22976-23595/ W/System.err: at java.lang.Thread.run(Thread.java:818)
以下代码我用于从ftp下载:
FTPClient client = new FTPClient();
client.setAutoNoopTimeout( 30000);
client.connect(FTP_HOST_DOWNLOAD,FTP_DOWNLOAD_PORT);
client.setPassive(true);
client.login(FTP_DOWNLOAD_USER, FTP_PASS_DOWNLOAD);
client.setType(it.sauronsoftware.ftp4j.FTPClient.TYPE_BINARY);
Log.d("Dir current",""+client.currentDirectory());
client.changeDirectory("/Private/testftp");
Log.d("Dir current",""+client.currentDirectory());
File file_local = new File(Environment.getExternalStorageDirectory() + File.separator + LOCAL_FILE_DOWNLOAD);
client.download(FILE_DOWNLOAD, file_local, new MyTransferListener());
错误代码426用于主机连接,但发生了与FTP的连接。