java+ftp+421错误,FTP连接超时421:解析器错误

The question has beed edited. I am trying to list all the files in a FTP directory - and though the code works fine when run in a normal Netbeans project, when using the same code in a Maven project its results in a connection timed out 421 . How can I get rid of this?

Code:

FTPClient ftpClient = new FTPClient();

ftpClient.connect(host, 21);

ftpClient.login(user, pass);

ftpClient.enterLocalPassiveMode();

ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);

ftpClient.configure(conf);

inputStream = FTPUtil.downloadSingleFile(ftpClient, filePath);

ftpClient.list(); // It works

ftpClient.listNames("/"); // It works

ftpClient.changeWorkingDirectory("/"); // It works

FTPFile[] files = ftpClient.listFiles("/");// It hangs and stops 421 connection timed out

The FileZilla log is:-

(000370)04-04-2013 16:04:32 - (not logged in) (127.0.0.1)> Connected, sending welcome message...

(000370)04-04-2013 16:04:32 - (not logged in) (127.0.0.1)> 220 ftp connection started...

(000370)04-04-2013 16:04:32 - (not logged in) (127.0.0.1)> USER raja

(000370)04-04-2013 16:04:32 - (not logged in) (127.0.0.1)> 331 Password required for raja

(000370)04-04-2013 16:04:32 - (not logged in) (127.0.0.1)> PASS ****

(000370)04-04-2013 16:04:32 - raja (127.0.0.1)> 230 Logged on

(000370)04-04-2013 16:04:32 - raja (127.0.0.1)> TYPE I

(000370)04-04-2013 16:04:32 - raja (127.0.0.1)> 200 Type set to I

(000370)04-04-2013 16:04:32 - raja (127.0.0.1)> PASV

(000370)04-04-2013 16:04:32 - raja (127.0.0.1)> 227 Entering Passive Mode (127,0,0,1,237,187)

(000370)04-04-2013 16:04:32 - raja (127.0.0.1)> SYST

(000370)04-04-2013 16:04:32 - raja (127.0.0.1)> 215 UNIX emulated by FileZilla

(000366)04-04-2013 16:04:33 - raja (127.0.0.1)> 421 Connection timed out.

The Client side exceptions are:-

LTzZc.png

解决方案

There is a serious issue in the apache-commons 1.4.1 in handling the parsing exception when the FTP server returns null against SYST command . I tried using version 3.2 and the issue got resolved.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值