欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ftp4j提示java.net.SocketException: Connection reset的解决  

程序员文章站 2022-07-15 16:35:17
...
系统的自动更新FTP服务器,其他计算机连接都没有问题,包括xp、server2008、win7、win8,简体和繁体。

今天发现一台简体win7无法自动更新,提示错误如下:
java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
        at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
        at sun.nio.cs.StreamDecoder.read(Unknown Source)
        at sun.nio.cs.StreamDecoder.read0(Unknown Source)
        at sun.nio.cs.StreamDecoder.read(Unknown Source)
        at java.io.InputStreamReader.read(Unknown Source)
        at it.sauronsoftware.ftp4j.NVTASCIIReader.readLine(NVTASCIIReader.java:1
05)
        at it.sauronsoftware.ftp4j.FTPCommunicationChannel.read(FTPCommunication
Channel.java:142)
        at it.sauronsoftware.ftp4j.FTPCommunicationChannel.readFTPReply(FTPCommu
nicationChannel.java:185)
        at it.sauronsoftware.ftp4j.FTPClient.openPassiveDataTransferChannel(FTPC
lient.java:3179)
        at it.sauronsoftware.ftp4j.FTPClient.openDataTransferChannel(FTPClient.j
ava:3113)
        at it.sauronsoftware.ftp4j.FTPClient.list(FTPClient.java:2019)
        at it.sauronsoftware.ftp4j.FTPClient.list(FTPClient.java:2193)
        at cn.stjauns.logan.updater.Updater.getRemotefiles(Updater.java:199)
        at cn.stjauns.logan.updater.Updater.doUpdate(Updater.java:58)
        at cn.stjauns.logan.updater.Starter.main(Starter.java:18)

关闭win7自带防火墙,一切正常。

上百度查询,无果。
上google查询,答案见:http://*.com/questions/10166337/ftp-error-while-downloading-uploading-with-ftp4j-library-in-java-application。

引用

Apparently there is a bug on the Windows 7 firewall related to using FTP on IPv6 that would explain your problem. See bug report here.

Any one of the following workarounds should suffice to fix it:

Run the following as an administrator in a Windows console:

netsh advfirewall set global StatefulFtp disable

Run the JVM with the option: -Djava.net.preferIPv4Stack=true


打开win7防火墙,以管理员身份运行cmd,运行如下命令:
netsh advfirewall set global StatefulFtp disable
问题解决。