+1 vote
by (320 points)
edited

Hello,

I want to know how much the file size has been uploaded from the Rebex FTP log.

The file size information is not displaying in the Rebex FTP log information.

But FileZilla is displaying the uploaded file size information in the log.

Please help me to print the uploaded file size information in the Rebex log same as FileZilla.

Please see the below image url to understand the above scenario.

http://screencast.com/t/MfZaVpa9

Thanks Naga Suresh D

Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (58.9k points)
edited

Please use the Ftp.TransferProgressChanged event to log the number of transferred bytes and the time it took to transfer a file. See this sample code which demonstrates it:

Ftp ftp = new Ftp();
ftp.LogWriter = new FileLogWriter("log.txt", LogLevel.Info);

ftp.TransferProgressChanged += ftp_TransferProgressChanged;

ftp.Connect("test.rebex.net");
ftp.Login("demo", "password");
ftp.GetFile("/pub/test/test.zip", @"C:\temp\test.zip");

ftp.Disconnect();

void ftp_TransferProgressChanged(object sender, FtpTransferProgressChangedEventArgs e)
{
    if (e.TransferState == TransferProgressState.FileTransferred)
    {
        Ftp ftp = (Ftp)sender;
        if (ftp.LogWriter != null)
        {
            long seconds = 0;

            if(e.BytesPerSecond > 0)
                seconds = e.BytesTransferred / e.BytesPerSecond;

            ftp.LogWriter.Write(LogLevel.Info, typeof(Ftp), 0, "Status", string.Format("File transfer succeeded. Transfered {0} bytes in {1} seconds.", e.BytesTransferred, seconds));
        }
    }
}
by (320 points)
edited

Thank you.

...