스크립트를 실행하면 다운로드하는 동안 처리량이 출력됩니다. 파일을 다운로드한 후 파일의 총 처리량 속도를 얻을 수 있는 방법이 있습니까?
내 스크립트:
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
}