FTP上传文件报的异常,我基本代码如下:
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 方法会报异常throws a java.net.SocketException:
这是一个java 7 在windows上的bug
解决办法:
用administrator用户登陆使用命令行执行:
netsh advfirewall set global StatefulFTP disable
即可。