WinSCP .NET assembly (PowerShell) PutFiles from UNC path only uploads 1 file
Hello,
I'm using WinSCP 5.7.6.0 and the 5.7.6.0 WinSCPnet.dll file.
I have looked at the many examples and written my scripts accordingly.
My upload script has the problem that it only uploads 1 file, even if multiple are present. If there are 3 files I would need to run the script 3 times. I have tried both using
I have played with
Does anyone see what I'm doing wrong, or is this really a bug?
Below is the script for reference:
Thank you!
I'm using WinSCP 5.7.6.0 and the 5.7.6.0 WinSCPnet.dll file.
I have looked at the many examples and written my scripts accordingly.
My upload script has the problem that it only uploads 1 file, even if multiple are present. If there are 3 files I would need to run the script 3 times. I have tried both using
PutFiles
as SynchronizeDirectories
with option Remote
. Both have the same behaviour wich leads me to believe it my having some to do with me using a UNC path as local folder.
I have played with
TranferOptions.FileMask
, I have added *.*
to my localPath
and remotePath
. But this does not make any difference. Only 1 file gets uploaded.
Does anyone see what I'm doing wrong, or is this really a bug?
Below is the script for reference:
#Start Write-Host ("Start script.") try { # Load WinSCP .NET assembly Add-Type -Path "c:\program files (x86)\winscp\WinSCPnet.dll" # Setup session options $sessionOptions = New-Object WinSCP.SessionOptions $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp $sessionOptions.HostName = "**********" $sessionOptions.PortNumber = 0000 $sessionOptions.UserName = "**********" $sessionOptions.SshPrivateKeyPath = "C:\FTP\******\Private-Key\*******.ppk" $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 68:92:****************:15:5e:78" Write-Host ("Connecting.") $session = New-Object WinSCP.Session # Upload files try { # Connect $session.Open($sessionOptions) $localPath = "\\SOMESERVER.fqdn\EDI\SOMEFOLDER\TEST\EXPORT\" $remotePath = "/TEST/IMPORT/" $backupPath = "\\SOMESERVER.fqdn\EDI\SOMEFOLDER\TEST\SAVE\" #File list: Write-Host ("File list: ") #transferoptions #$transferOptions = New-Object WinSCP.TransferOptions #$transferOptions.FileMask = "*.*" # Upload files, collect results $transferResult = $session.PutFiles(($localPath + "*.*"), ($remotePath + "*.*"), $False) # Iterate over every transfer foreach ($transfer in $transferResult.Transfers) { # Success or error? if ($transfer.Error -eq $Null) { Write-Host ("Upload of {0} succeeded, moving to save" -f $transfer.FileName) # Upload succeeded, move source file to backup Move-Item $transfer.FileName $backupPath -force } else { Write-Host ("Upload of {0} failed: {1}" -f $transfer.FileName, $transfer.Error.Message) } } #End of files: Write-Host ("End of files. ") } finally { # Disconnect, clean up $session.Dispose() Write-Host ("Disconnected.") } exit 0 } catch [Exception] { Write-Host $_.Exception.Message exit 1 }