java ftpclient 续传,FtpClient的上传文件= SocketException:连接复位

I'm trying to upload a simple txt file via FTP using XAMPP and FileZilla.

I'm using the Apache Commons Net 3.0.1 Library.

This is my code, very basic things:

FTPClient client = new FTPClient();

InputStream in = new ByteArrayInputStream("IT WORKS! :D".getBytes());

try {

client.connect("localhost");

client.login("user", "password");

client.enterLocalPassiveMode();

client.storeFile("textfile.txt", in);

} finally {

try {

in.close();

client.logout();

client.disconnect();

} catch (Exception e) {

}

}

But... storeFile() throws a java.net.SocketException:

Exception in thread "main" java.net.SocketException: Connection reset

at java.net.SocketInputStream.read(SocketInputStream.java:189)

at java.net.SocketInputStream.read(SocketInputStream.java:121)

at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)

at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)

at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)

at java.io.InputStreamReader.read(InputStreamReader.java:184)

at java.io.BufferedReader.fill(BufferedReader.java:154)

at java.io.BufferedReader.read(BufferedReader.java:175)

at org.apache.commons.net.io.CRLFLineReader.readLine(CRLFLineReader.java:58)

at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:310)

at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:290)

at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:474)

at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:547)

at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:596)

at org.apache.commons.net.ftp.FTP.pasv(FTP.java:945)

at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:719)

at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:551)

at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1704)

at ftpexample.ftpexample.main(ftpprova.java:17)

What's the problem?? :(

I tried also on an online hosting service, with the same result...

I wonder if this is a firewall or windows' services related problem??

解决方案

Solved by running this as administrator in the command prompt:

netsh advfirewall set global StatefulFTP disable

This is a Java 7 bug on Windows machines, it is reported here.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值