commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ward <wardloot...@gmail.com>
Subject [Commons NET]
Date Thu, 05 Mar 2009 14:44:51 GMT
Hi,

I'm using the Apache Commons NET library to ftp some files to a server.
I use the storeFileStream() method of FTPClient so I can write on the 
OutputStream and keep track of the progress during the upload
This is (a summary of) the code:

File file = File("location of file");
FileInputStream fis = new FileInputStream(file);
FTPClient ftpClient = new FTPClent();
ftpClient.connect(server-name);
ftpClient.login(user,pass);
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
OutputStream os = ftpClient.storeFileStream(file.getName());
byte buf[] = new byte[1024];
int len;
long totalLength = file.length();
long bytesRead = 0;
long percent;
while ((len = fis.read(buf)) > 0) {
     os.write(buf, 0, len);
     bytesRead += len;
     percent = (100 * bytesRead / totalLength);
}
fis.close();
os.close();
ftpClient.disconnect();

This seems to work fine: files get uploaded.
But when I take a closer look at the uploaded files, I notice they 
aren't uploaded completely.
The uploaded files are all shorter than the original files on my disk
The difference is alway around the 59-60kb
What could be the reason for that?
Is there something wrong with the copy-ing-structure I use between the 2 
streams?

Thanks for anwering

Ward

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message