FTP下载文件问题

guojiao123 2012-09-20 03:01:22
使用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;
}
...全文
166 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangzhonglong456 2012-09-27
  • 打赏
  • 举报
回复
你都没结果贴 祝没人回答!!
金兄 2012-09-27
  • 打赏
  • 举报
回复
我的建议,多打日志,多Debug观察,你这代码,我表示 看不出啥问题

+ 167765087 java开发技术交流

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧