我可以從 WinSCP 腳本獲得吞吐速度嗎?

我可以從 WinSCP 腳本獲得吞吐速度嗎?

我看到當我運行我的腳本時,它在下載時輸出吞吐量,有沒有辦法獲得文件下載後的總吞吐量?

我的腳本:

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

腳本.txt

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

答案1

你可以自己計算一下。

我建議你將腳本轉換為使用 WinSCP .NET 組件的 PowerShell 腳本

然後你可以在通話之前和之後花一些時間Session.GetFiles並計算速度:

$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)

完整的腳本如下。它是基於WinSCP.NET 程式集的官方 PowerShell 範例

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
}

相關內容