This is basically what .NET assembly does internally. In other words, it's not limitation of the .NET assembly. It's how WinSCP console works.
- martin
WinSCP.com /script=script.txt 1> x.x 2>&1
x.x
.
OutputDataReceived
. That progress information is not exposed anyhow in the .NET assembly API.
synchronize local
yours is a synchronize remote
.
synchronize local -nopermissions -preservetime -transfer="binary" -criteria="time" -- "I:\alldata\inetpub\wwwroot\offers" "/offers/"
"Local 'I:\alldata\inetpub\wwwroot\offers\ALAE' <= Remote '/offers/ALAE'"
OutputDataReceived
is not being fired or recognized correctly.
winscp> synchronize remote -nopermissions -preservetime -transfer="binary" -criteria="time" -- "c:\synctest" "/synctest"
Comparing...
Local 'c:\synctest' => Remote '/synctest'
Synchronizing...
Local 'c:\synctest' => Remote '/synctest'
c:\synctest\aaa.txt | 3 B | 0,0 KB/s | binary | 100%
c:\synctest\bbb.txt | 3 B | 0,2 KB/s | binary | 100%
c:\synctest\ccc.txt | 3 B | 0,4 KB/s | binary | 100%
$synchronizationResult
(SynchronizationResult
class).
$logPath
has the info I would like to print on screen. OutputDataReceived
displays text at startup, and then whenever the server times out and attempts reconnect, but no other time.
param (
$localPath = $PSScriptRoot,
$remotePath = '/offers/',
$logPath = $PSCommandPath.replace('ps1', 'log')
)
Add-Type -Path ([IO.Path]::Combine($PSScriptRoot, 'WinSCPnet.dll'))
#####################################################################################################################
### Session.OutputDataReceived event handler
#####################################################################################################################
function OutputDataReceived {
param($e)
Write-Host $e
}
#####################################################################################################################
### Session.FileTransferred event handler
#####################################################################################################################
function FileTransferred {
param($e)
write-host $e
}
# Main script
try {
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Ftp
HostName = 'site'
UserName = 'user'
Password = 'pwd'
FtpSecure = [WinSCP.FtpSecure]::Explicit
TlsHostCertificateFingerprint = 'fingerprint'
}
$session = New-Object WinSCP.Session
try {
# event handlers
# Will continuously report progress of synchronization
$session.add_FileTransferred( { FileTransferred($_) } )
$session.add_OutputDataReceived( { OutputDataReceived($_) } )
$session.DebugLogLevel = -1
$session.SessionLogPath = $logPath
# Connect
$session.Open($sessionOptions)
$synchronizationResult = $session.SynchronizeDirectories(
[WinSCP.SynchronizationMode]::Local, $localPath, $remotePath, $False, $False)
# Throw on any error
$synchronizationResult.Check()
}
finally {
# Disconnect, clean up
$session.Dispose()
}
exit 0
}
catch {
Write-Host "Error: $($_.Exception.Message)"
exit 1
}