commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Cole" <sc...@camsbycbs.com>
Subject Re: [Commons NET]
Date Thu, 05 Mar 2009 16:42:47 GMT
I think you need to call the FTPClient completePendingCommand() method.

Here's the example from API documentation...

For example, 
 InputStream input;
 OutputStream output;
 input  = new FileInputStream("foobaz.txt");
 output = ftp.storeFileStream("foobar.txt")
 if(!FTPReply.isPositiveIntermediate(ftp.getReplyCode())) {
     input.close();
     output.close();
     ftp.logout();
     ftp.disconnect();
     System.err.println("File transfer failed.");
     System.exit(1);
 }
 Util.copyStream(input, output);
 input.close();
 output.close();
 // Must call completePendingCommand() to finish command.
 if(!ftp.completePendingCommand()) {
     ftp.logout();
     ftp.disconnect();
     System.err.println("File transfer failed.");
     System.exit(1);
 }
----- Original Message ----- 
From: "Ward" <wardlootens@gmail.com>
To: "Commons Users List" <user@commons.apache.org>
Sent: Thursday, March 05, 2009 9:44 AM
Subject: [Commons NET]


> 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
> 
> 


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


Mime
View raw message