É fácil com o assembly WinSCP .NET e seu Session.EnumerateRemoteFiles
method :
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = "host"
UserName = "user"
Password = "password"
SshHostKeyFingerprint = "fingerprint"
}
Write-Host "Connecting..."
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)
Write-Host "Calculating..."
$sum =
$session.EnumerateRemoteFiles(
"/remote/path", $Null, [WinSCP.EnumerationOptions]::AllDirectories) |
Measure-Object -Property Length -Sum
Write-Host "Size is $($sum.Sum)"
(eu sou o autor do WinSCP)