如何解决从 Filezilla 连接到 FTP 服务器,但从 Android 中的 ftpClient Apache Commons 返回 530
我想从 Android 向 FTP 服务器发送一些文件。我有服务器 IP 地址、用户名和密码。我尝试从 Filezilla 连接到它并且它可以工作,但是,如果我尝试从 Android 连接它会失败。我从 ftpClient.getReplyCode()
获得状态代码 530。
根据https://en.wikipedia.org/wiki/List_of_FTP_server_return_codes,状态码表示登录无效。 ftpClient.login
返回 false。
所以我尝试用 node.js 挂载一个 FTP 服务器,并且可以完美地连接和上传文件。然后我尝试使用 username: demo 和 password: password 连接到另一个测试服务器 ftp://test.rebex.net/ 并且登录也有效(上传文件失败,因为它是一个测试帐户)。
但是为什么我无法从 Android 而不是从 Filezilla 登录到该特定服务器?
我的代码:
uploading_to_local_server = true;
FTPClient ftpClient = new FTPClient();
try {
if(port == 0){
ftpClient.connect(ftpserver);
}else {
ftpClient.connect(ftpserver,port);
}
ftpClient.setSoTimeout(10000);
ftpClient.enterLocalPassiveMode();
Log.d(TAG,"FTP. TRYING TO LOGIN ");
Boolean login_response = ftpClient.login(ftp_usr,ftp_psw);
mreplyCode = ftpClient.getReplyCode();
Log.d(TAG,"FTP. RESPONSE " + mreplyCode);
if (login_response) {
Log.d(TAG,"FTP. VIDEOS TO UPLOAD: LOGGED SUCCESFULLY");
//Logged.
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE);
//iterating through the videos
String video_upload_result = "UkNown Error";
ArrayList<HashMap<String,String>> list_videos_to_upload = dataBaseHelper.getVideoslocalserverH();
for (int counter = 0; counter < list_videos_to_upload.size(); counter++) {
video_upload_result = "UkNown Error";
//list_videos_to_upload.get(counter).put("imei",IMEI);
String video_path = list_videos_to_upload.get(counter).get("dir_route");
String video_name = list_videos_to_upload.get(counter).get("video_name");
String vid_id = list_videos_to_upload.get(counter).get("id");
String sync_status = list_videos_to_upload.get(counter).get("sync");
Log.d(TAG,"VIDEOS TO UPLOAD: " + video_path + " ID: " + vid_id);
//Log.d(TAG,"WIFI STATUS: " + mWifi.isConnected() + " DATA STATUS: " + wData.isConnected());
video_upload_result = try_upload_video_to_ftpserver(ftpClient,video_name,remote_path,video_path);
Log.d(TAG,"VIDEOS TO UPLOAD: " + video_path + " RESULT: " + video_upload_result);
if(video_upload_result.equals("Succes")) {
Log.d(TAG,"TESTING UPLOAD: VIDEO ID: "+ vid_id);
dataBaseHelper.modVideos_Localserver(Collections.singletonList(vid_id));
}else if(video_upload_result.equals(video_path + ": open Failed: ENOENT (No such file or directory)")){
Log.d(TAG,"TESTING UPLOAD: ERROR CATCHED. FILE NOT FOUND: "+ vid_id);
dataBaseHelper.modVideos_Localserver(Collections.singletonList(vid_id));
}
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
Log.d(TAG,"Error Sleeping thread");
e.printstacktrace();
}
}
}
ftpClient.logout();
ftpClient.disconnect();
}catch (IOException e) {
e.printstacktrace();
}
Log.d(TAG,"UPLOADING LOOP ENDED: ");
uploading_to_local_server = false;
编辑:
终于成功了。
原来服务器只接受通过 ftps 的连接。 所以我改变了: FTPClient ftpClient = new FTPClient(); 为了 FTPSClient ftpClient = new FTPSClient("TLS",false);
我设法连接到服务器但仍然无法上传视频,因为服务器也只接受加密数据,所以我补充道: ftpClient.execPROT("P"); // 加密数据通道
现在我终于可以将视频上传到该服务器了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。