Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting Upload Speed of FTP Upload C#

Posted on 2009-07-05
1
Medium Priority
?
1,945 Views
Last Modified: 2013-11-29
Im trying to get the upload speed from my client to server.
try
                        {
                            Stream strm = ftp.GetRequestStream();
                            content = fs.Read(buff, 0, bufflength);
                            
                            while (content != 0)
                            {
                                strm.Write(buff, 0, content);
                                transfered += content;
                                progressBar1.Value = transfered;
                                
                                content = fs.Read(buff, 0, bufflength);
                                
                            }
                            strm.Close();
                            fs.Close();
}

Open in new window

0
Comment
Question by:davito93
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 21

Accepted Solution

by:
MogalManic earned 2000 total points
ID: 24784385
Just put timing code something like below: (Note that I am only timing the FTP stream writing  so the TotalTime will be less than the real time (EndTime-StartTime).  This is just the speed of the FTP transfer)

If you want time want to give the users real time transfer estimates then you will have to create an event and do the same computations for each strm.Write()

try
{
    Stream strm = ftp.GetRequestStream();
    content = fs.Read(buff, 0, bufflength);
    DateTime startTime=DateTime.Now
    DateTime intervalStart, intervalEnd;
    TimeSpan TotalTime=TimeSpan.Zero;
    while (content != 0)
    {
	IntervalStart=DateTime.Now;
        strm.Write(buff, 0, content);
        IntervalEnd=DateTime.Now
 
	//Do something like this if you want to provide user with real time tranfer rates
	//RaiseTransferSpeedEvent(IntervalEnd.Subtract(IntervalStart));
	TotalTime.Add(IntervalEnd.Subtract(IntervalStart));
        transfered += content;
        progressBar1.Value = transfered;
        
        content = fs.Read(buff, 0, bufflength);
        
    }
    DateTime FinishTime = DateTime.Now
    strm.Close();
    fs.Close();
	
    long TotalSize=transfered;
    long TransferRate = TotalSize/TotalTime.TotalSeconds;  //Transfer rate in bytes per second
    TransferRate = TransferRate * 8                        //Transfer rate in bits per second
    float TransferMB = TransferRate / (1000000.0)          //Transfer rate in MegaBits per second (baud)
}

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
We recently endured a series of broadcast storms that caused our ISP to shut us down for brief periods of time. After going through a multitude of tests, we determined that the issue was related to Intel NIC drivers on some new HP desktop computers …
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question