2 kingleeyn kingleeyn 于 2016.04.18 19:43 提问

Software caused connection abort: recv failed

vm搭建了CentOS nginx vsftpd
目前使用ftp客户端可以实现文件传递,但使用java代码junit测试却报错,百思不得其解,求助大神
报错提示:
java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:150)
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:314)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:483)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:608)
at org.apache.commons.net.ftp.FTP.port(FTP.java:932)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:812)
at org.apache.commons.net.ftp.FTPClient._storeFile(FTPClient.java:633)
at org.apache.commons.net.ftp.FTPClient.__storeFile(FTPClient.java:624)
at org.apache.commons.net.ftp.FTPClient.storeFile(FTPClient.java:1976)
at com.taotao.controller.FTPTest.testFtpClient(FTPTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
测试类
@Test
public void testFtpClient() throws Exception {
//创建一个FtpClient对象
FTPClient ftpClient = new FTPClient();
//创建ftp连接。默认是21端口
ftpClient.connect("192.168.44.129", 21);
//登录ftp服务器,使用用户名和密码
ftpClient.login("ftpuser", "ftpuser");
//上传文件。
//读取本地文件
FileInputStream inputStream = new FileInputStream(new File("E:\BaiduDownload\11.jpg"));
//设置上传的路径
ftpClient.changeWorkingDirectory("/home/ftpuser/www/images");
//修改上传文件的格式
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
//第一个参数:服务器端文档名
//第二个参数:上传文档的inputStream
ftpClient.storeFile("11.jpg",inputStream);
//关闭连接
inputStream.close();
ftpClient.logout();

5个回答

kingleeyn
kingleeyn   2016.04.19 15:21
已采纳

问题已经解决了。代码方面没有问题。问题出现在客户机的防火墙限制了文件的传递。具体的分析是win7的防火墙有家庭和公用两个部分。我只禁止了家庭部分的防火墙,还有公用的防火墙没有关闭。

kingleeyn
kingleeyn   2016.04.18 19:47

刚开始接触ftp服务器的使用,测试类是跟着视频打的。希望能指出问题的原因和解决的办法。提示行是:ftpClient.storeFile("11.jpg",inputStream);

CSDNXIAOC
CSDNXIAOC   2016.04.18 19:52

 Software
caused
connection
abort: recv
failed

java
.net
.SocketException: Software
caused
connection
abort: recv
failed

at java
.net
.SocketInputStream.socketRead0(......
答案就在这里:Software caused connection abort: recv failed
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

bealing
bealing   Rxr 2016.04.19 12:17

FileInputStream inputStream = new FileInputStream(new File("E:\BaiduDownload\11.jpg"));
文件路径改为"E:\BaiduDownload\11.jpg"

kingleeyn
kingleeyn Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
一年多之前 回复
kingleeyn
kingleeyn   2016.04.19 13:56

源代码是有两个\,被网页吃掉了一个。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!