WinSCP dll (powershell) putfiles long path name
I created a powershell script to transfer files from local path to remote path, when the file path is greater than 260 winscp throws exception and stops transfer, my question is can i ignore the error of long path name and continue transfer the rest of files? also i tried to get all the files less than 250 characters but it doesn't work.
here is my script, thanks
here is my script, thanks
param ( $localPath = "F:\Test1\*", $remotePath = "/Test1" ) try { # Load WinSCP .NET assembly Add-Type -Path "WinSCPnet.dll" # Setup session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "203.59.234.21" UserName = "ftpuser" Password = "eight*eight=64" SshHostKeyFingerprint = "ssh-rsa 1024 2i34SDb4+UdjGY8D20qJpbiTWP9Vly51ILjGN96/5bY=" } $session = New-Object WinSCP.Session try { #transferoptions $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary # Connect $session.Open($sessionOptions) $files=(Get-ChildItem -Path $localPath -Recurse | where {$_.fullname.Length -lt 250}) foreach ($Fileinfo in $files) { $session.PutFiles($Fileinfo.FullName , $remoteFilePath) Write-Host ($Fileinfo.FullName) } } finally { $session.Dispose() } } catch { Write-Host $_.Exception.Message exit 1 }