0

I see that when I run my script, it outputs the throughput while it is downloading, is there a way to get the total throughput speed of the file after it has been downloaded?

My Script:

WinSCP.exe /console /script=script.txt /log=my_log.log > output

Script.txt

option batch abort
option confirm off
open IMC
get "/home/ftp/download/01_MBytes.txt" "C:\downloads\01_MBytes.txt"
exit

1 Answer 1

0

You can calculate it yourself.

I'd suggest you to convert your script to PowerShell script that uses WinSCP .NET assembly.

Then you can take a time before and after the call to the Session.GetFiles and calculate the speed:

$remotePath = "/home/ftp/download/01_MBytes.txt"
$localPath = "C:\downloads\01_MBytes.txt"

Write-Host "Starting download"
$start = Get-Date
$session.GetFiles($remotePath, $localPath).Check()
$duration = (Get-Date) - $start
$size = (Get-Item $localPath).Length / 1024
$speed = $size / $duration.TotalSeconds

Write-Host "Downloaded file $remotePath to $localPath"
Write-Host ("Size {0:N0} KB, Time {1:hh\:mm\:ss}" -f $size, $duration)
Write-Host ("Speed {0:N0} KB/s" -f $speed)

A full script is below. It's based on the official PowerShell example for WinSCP.NET assembly.

try
{
    # Load WinSCP .NET assembly
    Add-Type -Path "WinSCPnet.dll"

    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
    $sessionOptions.HostName = "example.com"
    $sessionOptions.UserName = "user"
    $sessionOptions.Password = "mypassword"
    $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xxxxxxxxxxx...="

    $session = New-Object WinSCP.Session

    try
    {
        # Connect
        $session.Open($sessionOptions)

        $remotePath = "/home/ftp/download/01_MBytes.txt"
        $localPath = "C:\downloads\01_MBytes.txt"

        Write-Host "Starting download"
        $start = Get-Date
        $session.GetFiles($remotePath, $localPath).Check()
        $duration = (Get-Date) - $start
        $size = (Get-Item $localPath).Length / 1024
        $speed = $size / $duration.TotalSeconds

        Write-Host "Downloaded file $remotePath to $localPath"
        Write-Host ("Size {0:N0} KB, Time {1:hh\:mm\:ss}" -f $size, $duration)
        Write-Host ("Speed {0:N0} KB/s" -f $speed)
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }

    exit 0
}
catch [Exception]
{
    Write-Host $_.Exception
    exit 1
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .