FTP下载文件问题
使用FTPClient从FTP服务器上下载文件到本地,本地可以生成一个正确的文件名,但大小是0,请问谁遇到过这种问题
代码如下:
执行到ftp.retrieveFile(fileName, is)时,就一直卡在那不动了
public static boolean downLoadFile(String ip, String port, String username,
String password, String serverpath, String localPath,
String fileName) {
// 初始表示下载失败
boolean success = false;
FTPClient ftp = new FTPClient();
try {
int reply;
ftp.connect(ip, Integer.parseInt(port));
// 如果采用默认端口,可以使用ftp.connect(url)的方式直接连接FTP服务器
System.out.println("FTP连接登录");
ftp.login(username, password);// 登录
reply = ftp.getReplyCode();
System.out.println("reply==="+reply);
if (!FTPReply.isPositiveCompletion(reply)) {
System.out.print("连接FTP服务器失败");
ftp.disconnect();
return success;
}
ftp.changeWorkingDirectory(serverpath);// 转移到FTP服务器目录
File localFile = new File(localPath + "/" + fileName);
OutputStream is = new FileOutputStream(localFile);
success = ftp.retrieveFile(fileName, is);
is.close();
ftp.logout();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return success;
}