FTP Log with File Size information while uploading the file into FTP

+1 vote
asked Sep 1, 2014 by Ftp (280 points)
edited Sep 1, 2014

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
answered Sep 1, 2014 by Tomas Knopp (58,890 points)
edited Sep 1, 2014

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));
        }
    }
}
commented Sep 1, 2014 by Ftp (280 points)
edited Sep 1, 2014

Thank you.

...