Transfer Status

0 votes
asked Sep 17, 2010 by Kyle Donohue (120 points)
edited Mar 21, 2011

Our company has purchased the SFTP and SSL product. I am using C# console apps to download files. Is there a code snippet anywhere that will show me how to display kbs/sec and % downloaded for the current file?

Applies to: Rebex FTP/SSL, Rebex SFTP

1 Answer

0 votes
answered Sep 20, 2010 by Vit Zyka (1,000 points)
edited Sep 20, 2010

Hello.

1) Getting transfer rate [kbs/sec]

Since Rebex (S)Ftp component 2010-03-11 Version 3.0.3723 the transfer rate can be obtained by setting TransferProgress event as follows:

ftp.Connect( ... );
ftp.Login(..., ...);
ftp.TransferProgress +=new FtpTransferProgressEventHandler(ftp_TransferProgress);
ftp.PutFile(...,...); or ftp.GetFile(...,...);

static void  ftp_TransferProgress(object sender, FtpTransferProgressEventArgs e)
{
  Console.WriteLine("Upload rate (B/sec): {0} \tBytes {1:D12} {2}",
        e.BytesPerSecond, e.BytesTransferred, e.Finished?"end":"");
}

2) Getting % of downloaded size

This can be solved similarly as previous question. There is no direct support for download/upload percentage but you can calculate this by exploiting the TransferProgess event as in the previous case. It containts e.BytesTransferred property. For percentage evaluation you need the total size of the file. The remote file size (in case of GetFile) can be obtained by ftp.GetFileLength(...); the size of the local file (in case of PutFile) by FileInfo info = new FileInfo(...); info.Length.

...