You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Luca Vercelli <lu...@alkeinformatica.com> on 2015/08/03 11:13:47 UTC
[io] cannot upload more files with ftp
Dear all,
I have a problem with FTP file upload of more than 1 file, using
storeFileStream().
I can connect to an FTP client, and I can upload 1 file. When I try to
upload a second file, the server disconnects.
Using commons-net 3.3 FTPClient. Here is a minimal Java code:
||||| public static void main(String[] args) throws IOException {
String host = "xxx";
String username = "xxx";
String password = "xxx";
String localFile1 = "xxx";
String localFile2 = "xxx";
String remoteFolder = "xxx";
FTPClient client = new FTPClient();
client.connect(host, 21);
client.login(username, password);
client.enterLocalPassiveMode();
client.setFileType(FTP.BINARY_FILE_TYPE);
client.changeWorkingDirectory(remoteFolder);
File localfile = new File(localFile1);
FTPFile[] files = client.listFiles(localfile.getName());
OutputStream os = client.storeFileStream(localfile.getName());
FileUtils.copyFile(localfile, os);
os.close();
localfile = new File(localFile2);
files = client.listFiles(localfile.getName());
System.out.println((files == null) ? null : files.length);
os = client.storeFileStream(localfile.getName());
FileUtils.copyFile(localfile, os);
os.close();
}
|
An exception is thrown at the second storeFileStream():
Exception in thread "main" java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at
java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:327)
at
java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:193)
at
java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:385)
at java.net.Socket.connect(Socket.java:546)
at
org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:894)
at
org.apache.commons.net.ftp.FTPClient._storeFileStream(FTPClient.java:688)
at
org.apache.commons.net.ftp.FTPClient.__storeFileStream(FTPClient.java:679)
at
org.apache.commons.net.ftp.FTPClient.storeFileStream(FTPClient.java:2007)
at Test.main(Test.java:39)
|
Do you have any idea?
Thank you.
|
--
Luca Vercelli