1、背景
使用ftpclient 从ftp服务器上下载文件到指定文件夹
ftp服务器搭建好之后,使用FileZilla软件连接正常,下载也正常,如下图:
然而,使用java代码使用FtpClient登陆服务器正常,在进行下载的时候报错如下
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:920)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:785)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3409)
at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:3339)
at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:3016)
at com.iflytek.ahslyy.ftpconverter.utils.FtpUtil.download(FtpUtil.java:143)
at com.iflytek.ahslyy.ftpconverter.service.FtpService.download(FtpService.java:62)
at com.iflytek.ahslyy.ftpconverter.service.HldConverterService.hldConverter(HldConverterService.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
在测试环境测试的好好的,没想到上线遇到这种问题,害,命途多舛啊。
找了很久的原因终于在这篇文章中找到了答案
https://www.656463.com/wenda/sjljsdFTPSClienttjzcs_354
如文章中所说
删除setUseEPSVwithIPv4(true); 在这里是关键。
要通过服务器验证,您需要使用setRemoteVerificationEnabled(false);文章来源:https://www.toymoban.com/news/detail-653037.html
然后再进行测试,成功下载!具体啥原因咱也不知道,有清楚的小伙伴,麻烦留言告知下,感谢!文章来源地址https://www.toymoban.com/news/detail-653037.html
到了这里,关于FtpClient请求ftp服务器报Connection refused: connect的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!