java ftp文件上传

时间:2011-09-16 19:57:13

标签: java ftp

我在windows中使用filezilla运行ftp服务器。我能够连接到它,但当我尝试上传文件或列出文件时,我得到一个例外。我正在尝试此页面中的示例http://www.kodejava.org/examples/357.html

Login success...
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
at java.io.BufferedWriter.flush(BufferedWriter.java:254)
at org.apache.commons.net.ftp.FTP.__send(FTP.java:496)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:470)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:547)
at org.apache.commons.net.ftp.FTP.port(FTP.java:872)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:667)
at org.apache.commons.net.ftp.FTPClient.listNames(FTPClient.java:2528)
at org.apache.commons.net.ftp.FTPClient.listNames(FTPClient.java:2574)

在服务器日志中,我看到以下内容

(000032)9/16/2011 14:38:28 PM - (not logged in) (127.0.0.1)> Connected, sending welcome message...
(000032)9/16/2011 14:38:28 PM - (not logged in) (127.0.0.1)> 220-FileZilla Server version 0.9.39 beta
(000032)9/16/2011 14:38:28 PM - (not logged in) (127.0.0.1)> 220-written by Tim Kosse    (Tim.Kosse@gmx.de)
(000032)9/16/2011 14:38:28 PM - (not logged in) (127.0.0.1)> 220 Please visit http://sourceforge.net/projects/filezilla/
(000032)9/16/2011 14:38:28 PM - (not logged in) (127.0.0.1)> USER reverb0253
(000032)9/16/2011 14:38:28 PM - (not logged in) (127.0.0.1)> 331 Password required for reverb0253
(000032)9/16/2011 14:38:28 PM - (not logged in) (127.0.0.1)> PASS ********
(000032)9/16/2011 14:38:28 PM - reverb0253 (127.0.0.1)> 230 Logged on
(000032)9/16/2011 14:38:40 PM - reverb0253 (127.0.0.1)> disconnected.

当我点击类似client.storeFile()时,服务器日志已断开连接。我正在使用apache commons-net 3.0.1

1 个答案:

答案 0 :(得分:0)

当您执行目录列表或文件传输时,FTP会打开另一个连接。防火墙或安全软件可能会阻止连接。这称为“数据通道”,在会话期间协商确切的端口。在数据通道打开之前,我希望在服务器日志中看到PORT或PASV。您可能必须在客户端使用wireshark来查看您要发送的内容。