Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

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).
Marwa

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
}