Eddy
Eddy

Reputation: 3713

FTPSClient hangs on storeFile - file sent arrives with zero bytes

I'm using org.apache.commons.net.ftp.FTPSClient for sending files to another server. But the program hangs after

boolean stored = client.storeFile(fileName, is);

The file is sent but on the server it has zero bytes.

I tried sending the same file to the same server using Filezilla and it gets transferred with no problems, so I don't think this is a firewall issue.

I also made sure that my InputStream is reading the file by printing its contents.

Here's my code:

FTPSClient client = new FTPSClient();
InputStream is = null;

client.connect(AppValues.ftpurl);
client.login(AppValues.ftpname, AppValues.ftppass);
is = new FileInputStream("C:\\Users\\path\\filename");
boolean stored = client.storeFile(fileName, is);
System.out.println("Stored? " + stored);

The Stored printout is never called, and the file arrives with zero bytes.

What am I missing?

Upvotes: 1

Views: 1863

Answers (1)

P S M
P S M

Reputation: 1161

FTPClient client = = new FTPClient();
InputStream is = null;
client.connect(AppValues.ftpurl);
client.login(AppValues.ftpname, AppValues.ftppass);
client.setFileType(FTP.BINARY_FILE_TYPE); 
client.enterLocalPassiveMode();
is = new FileInputStream("C:\\Users\\path\\filename");
boolean stored = client.storeFile(fileName, is);
System.out.println("Stored? " + stored);

Upvotes: 1

Related Questions