FtpClient的上传文件= SocketException:连接复位 [英] FTPClient Uploading File = SocketException: Connection reset

查看:1275
本文介绍了FtpClient的上传文件= SocketException:连接复位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过上传使用XAMPP和FileZilla中的FTP一个简单的txt文件。
我使用的是阿帕奇共享网络3.0.1图书馆
这是我的code,很基本的东西:

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) {
    }
}


但是... storeFile()抛出一个java.net.SocketException异常:


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)


什么问题?? :( 我想也对在线托管服务,同样的结果...
我不知道这是否是防火墙或Windows的服务有关的问题?


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??

推荐答案

通过在命令提示符下运行这个以管理员身份解决

netsh advfirewall set global StatefulFTP disable

这是在Windows机器上的Java 7漏洞,这里报道

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

这篇关于FtpClient的上传文件= SocketException:连接复位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆