Upload progress to FTPClient

I use commons-net FTPClient to upload some files.
How can I get the download progress (number of bytes downloaded now)?

thanks

+4
source share
2 answers

Of course, just use CopyStreamListener . Below you will find an example (copied from the commons-io wiki) of extracting files, so you can easily change it in the opposite direction.

try { InputStream stO = new BufferedInputStream( ftp.retrieveFileStream("foo.bar"), ftp.getBufferSize()); OutputStream stD = new FileOutputStream("bar.foo"); 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) { ... } 
+4
source

I think that maybe we should use CountingOutputStream as it seems intended for this purpose?

Someone answers this here: Monitoring progress using Apache Commons FTPClient

0
source

Source: https://habr.com/ru/post/1401047/


All Articles