sun.net.ftp异常 PORT 192,168,0,80,9,205: 550 Permission denied.
我使用sun.net.ftp来连接linux的vsftp时,出现如下的异常(在windows下是没有的)
java.io.FileNotFoundException: PORT 192,168,0,80,9,205: 550 Permission denied.
at sun.net.ftp.FtpClient.readReply(FtpClient.java:236)
at sun.net.ftp.FtpClient.issueCommand(FtpClient.java:193)
at sun.net.ftp.FtpClient.openDataConnection(FtpClient.java:434)
at sun.net.ftp.FtpClient.put(FtpClient.java:594)
at org.lab24.util.FtpTool.processfile(FtpTool.java:193)
at org.lab24.util.FtpTool.upload(FtpTool.java:116)
at org.lab24.spider.Spider.run(Spider.java:55)
at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
at java.lang.Thread.run(Thread.java:619)
exception e in ftp upload(): java.io.FileNotFoundException: PORT 192,168,0,80,9,205: 550 Permission denied.
后来查过网上的解决方案,才知道:
该类默认使用的是Port模式传输数据,但实际上Linux配的是Pasv模式,所以传不过去,修改办法:
ftpclient.sendServer("quote PASV");
设置一下传输模式就可以传了。