WinSCP dll (powershell) putfiles long path name

Advertisement

Marwa
Guest

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

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 
}

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,040
Location:
Prague, Czechia

Re: WinSCP dll (powershell) putfiles long path name

WinSCP should support long paths. Make sure you have the latest version of WinSCP:
https://winscp.net/tracker/821

Though it can also be a server-side limitation.
Hard to tell without see an exact error message or even better a session log file (Session.SessionLogPath).

Reply with quote

Advertisement

You can post new topics in this forum