Android在ftp上上传文件 Android文件上传问题
我正试图上传我的ftp服务器上的图像,它并没有给我任何异常或错误,但在nt部署的图像。任何人都可以上传图像可以识别问题Android在ftp上上传文件 Android文件上传问题,android,file-upload,Android,File Upload,我正试图上传我的ftp服务器上的图像,它并没有给我任何异常或错误,但在nt部署的图像。任何人都可以上传图像可以识别问题 FTPClient con = new FTPClient(); try{ con.connect("host",21); con.login(username, pswd); con.setFileType(FTP.BINARY_FILE_TYPE); con.setFileTransferMode(FTP.ASCII_FILE_
FTPClient con = new FTPClient();
try{
con.connect("host",21);
con.login(username, pswd);
con.setFileType(FTP.BINARY_FILE_TYPE);
con.setFileTransferMode(FTP.ASCII_FILE_TYPE);
con.setSoTimeout(10000);
con.enterLocalPassiveMode();
if (con.login(username, pswd)) {
try {
File sFile = new File("mnt/sdcard/DCIM/download.jpg");
// connect.setText(sFile.toString());
BufferedInputStream buffIn = null;
buffIn = new BufferedInputStream(
new FileInputStream(sFile));
try {
String fileName = sFile.getName();
while (!dataUpResp) {
dataUpResp = con.storeFile(fileName,
buffIn);
// publishProgress("" + 10);
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.getMessage();
}
}
} catch (IOException e) {
}
您的代码中有2次登录,这不是一个问题吗
con.login(username, pswd); // 1st time
con.setFileType(FTP.BINARY_FILE_TYPE);
con.setFileTransferMode(FTP.ASCII_FILE_TYPE);
con.setSoTimeout(10000);
con.enterLocalPassiveMode();
if (con.login(username, pswd)) // 2nd time
另外,您没有对FTPClient使用注销/断开连接,并且流没有刷新和关闭功能。使用commons-net-3.2.jar和FileZilla FTP服务器的连接尝试了您的代码,效果很好 老兄。。。代码、日志等?请提供更多信息!就像你的代码一样!您确定您的文件路径正确吗?您缺少前导“/”所以我怀疑您没有。当我放置一些TextView来检查它时,我发现它没有穿过“if(con.login(username,pswd))”。。