How to trace time for FTP Upload

Hi,

I've written a windows application to upload the files to our ftp location using .NET v1.1. Now my requirement is to find out the time that will take to upload the selected files.

Inother words, how can i show the estimated time to transfer any file on the internet

Any suggestion are highly helpful to me..

Thanks and Regards,

Chakravarthy




Answer this question

How to trace time for FTP Upload

  • Spatulas

    Hi,

    Great logic. But can you tell me about how can i get the uploaded size of the current file

    Inother words, if i'm uploading a file to FTP Server, how do i get to know, howmuch data is being transferred to the FTP Site at any given time

    Regards



  • Ben Walling

    Hi!

    Simple way: time left = used time * downloaded size / total size

    Smooth way: keep last 3 (or 10) expected time values and display average of them (this will hide minor fluctuations).



  • luzippu

    cSocket.Send(buffer, bytes, 0);

    You must update estimated time after this line.


  • Rhubarb

    Here is the code to upload a file.

    Source: http://www.csharphelp.com/archives/archive9.html

    public void Upload(string fileName, bool resume)

    {

    if ( !this.loggedin ) this.Login();

    Socket cSocket = null ;

    long offset = 0;

    if ( resume )

    {

    try

    {

    this.BinaryMode = true;

    offset = GetFileSize( Path.GetFileName(fileName) );

    }

    catch(Exception)

    {

    // file not exist

    offset = 0;

    }

    }

    // open stream to read file

    FileStream input = new FileStream(fileName,FileMode.Open);

    if ( resume && input.Length < offset )

    {

    // different file size

    Debug.WriteLine("Overwriting " + fileName, "FtpClient");

    offset = 0;

    }

    else if ( resume && input.Length == offset )

    {

    // file done

    input.Close();

    Debug.WriteLine("Skipping completed " + fileName + " - turn resume off to not detect.", "FtpClient");

    return;

    }

    // dont create untill we know that we need it

    cSocket = this.createDataSocket();

    if ( offset > 0 )

    {

    this.sendCommand( "REST " + offset );

    if ( this.resultCode != 350 )

    {

    Debug.WriteLine("Resuming not supported", "FtpClient");

    offset = 0;

    }

    }

    this.sendCommand( "STOR " + Path.GetFileName(fileName) );

    if ( this.resultCode != 125 && this.resultCode != 150 ) throw new FtpException(result.Substring(4));

    if ( offset != 0 )

    {

    Debug.WriteLine("Resuming at offset " + offset, "FtpClient" );

    input.Seek(offset,SeekOrigin.Begin);

    }

    Debug.WriteLine( "Uploading file " + fileName + " to " + remotePath, "FtpClient" );

    while ((bytes = input.Read(buffer,0,buffer.Length)) > 0)

    {

    cSocket.Send(buffer, bytes, 0);

    }

    input.Close();

    if (cSocket.Connected)

    {

    cSocket.Close();

    }

    this.readResponse();

    if( this.resultCode != 226 && this.resultCode != 250 ) throw new FtpException(this.result.Substring(4));

    }



  • denken

    How do you upload file Do you use some FTPClient component or write own Post here sample how you upload and we will find the way.


  • How to trace time for FTP Upload