You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Apache Wiki <wi...@apache.org> on 2006/01/27 14:24:33 UTC

[Jakarta-commons Wiki] Update of "Net/FrequentlyAskedQuestions" by Guilherme Silva

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification.

The following page has been changed by Guilherme Silva:
http://wiki.apache.org/jakarta-commons/Net/FrequentlyAskedQuestions

The comment on the change is:
My Code needs an FTPClient ready to transfer files. Sorry about the english.

------------------------------------------------------------------------------
  in RAM.
  
  ----
- '''Q: The storeFile method of FTPClient class calls copyStream method of org.apache.commons.net.io.Utils. The method in Utils takes a CopyStreamListener listener as a parameter. Is there anyway I can have a listener when calling storeFile? This way i can get the update of the bytes transferred from another thread
+ '''Q: The storeFile method of FTPClient class calls copyStream method of org.apache.commons.net.io.Utils. The method in Utils takes a CopyStreamListener listener as a parameter. Is there anyway I can have a listener when calling storeFile? This way i can get the update of the bytes transferred from another thread'''
  
+ '''A:''' If you need to use a CopyStreamListener, you can manually open the connection using the method '''retrieveFileStream''' instead of storeFile and copy the contents from one file to another using the method '''copyStream'''.
+ 
+ {{{
+ 	try {
+             InputStream stO =
+                 new BufferedInputStream(
+                     ftp.retrieveFileStream(fnO),
+                     ftp.getBufferSize());
+ 
+             OutputStream stD =
+                 new FileOutputStream(fnD);
+ 
+             org.apache.commons.net.io.Util.copyStream(
+                     stO,
+                     stD,
+                     ftp.getBufferSize(),
+ /* I'm using the UNKNOWN_STREAM_SIZE constant here, but you can use the size of file too */
+                     org.apache.commons.net.io.CopyStreamEvent.UNKNOWN_STREAM_SIZE,
+                     new org.apache.commons.net.io.CopyStreamAdapter() {
+                         public void bytesTransferred(long totalBytesTransferred,
+                                 int bytesTransferred,
+                                 long streamSize) {
+                                 // Your progress Control code here
+                         }
+             });
+             ftp.completePendingCommand();
+ 	} catch (Exception e) { ... }
+ }}}
+ 
+ This snipet is a simple version of retrieveFile method. If you consult the original version, you will see that all you need to do is change the copyStream method according to your needs.
+ 

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