WinSCP .NET assembly (PowerShell) PutFiles from UNC path only uploads 1 file

Advertisement

Stan.Gobien
Joined:
Posts:
2
Location:
Belgium

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 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
}
Thank you!

Reply with quote

Advertisement

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

Re: WinSCP .NET assembly (powershell) putfiles from UNC path only uploads 1 file

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Stan.Gobien
Joined:
Posts:
2
Location:
Belgium

Thank you for your answer.
Thanks to the session log file I have now seen the error:
15:47:18.770 Status code: 3, Message: 521, Server: This server does not support operations to modify file attributes., Language:  
* 2016-02-03 15:47:18.770 (ETerminal) Permission denied.
* 2016-02-03 15:47:18.770 Error code: 3
* 2016-02-03 15:47:18.770 Error message from server: This server does not support operations to modify file attributes.
. 2016-02-03 15:47:18.770 Asking user:
. 2016-02-03 15:47:18.770 **Upload of file '***********.xml' was successful, but error occurred while setting the permissions and/or timestamp.**
. 2016-02-03 15:47:18.770 
. 2016-02-03 15:47:18.770 If the problem persists, turn off setting permissions or preserving timestamp. Alternatively you can turn on 'Ignore permission errors' option. ("Permission denied.
. 2016-02-03 15:47:18.770 Error code: 3
. 2016-02-03 15:47:18.770 Error message from server: This server does not support operations to modify file attributes.")
< 2016-02-03 15:47:18.770 Script: Upload of file '*************.xml' was successful, but error occurred while setting the permissions and/or timestamp.
< 2016-02-03 15:47:18.770 If the problem persists, turn off setting permissions or preserving timestamp. Alternatively you can turn on 'Ignore permission errors' option.
< 2016-02-03 15:47:18.770 Script: Permission denied.
< 2016-02-03 15:47:18.770 Error code: 3
< 2016-02-03 15:47:18.770 Error message from server: This server does not support operations to modify file attributes.
* 2016-02-03 15:47:18.785 (EScpSkipFile) **Upload of file '***************.xml' was successful, but error occurred while setting the permissions and/or timestamp.**
* 2016-02-03 15:47:18.785 
* 2016-02-03 15:47:18.785 If the problem persists, turn off setting permissions or preserving timestamp. Alternatively you can turn on 'Ignore permission errors' option.
* 2016-02-03 15:47:18.785 Permission denied.
* 2016-02-03 15:47:18.785 Error code: 3
* 2016-02-03 15:47:18.785 Error message from server: This server does not support operations to modify file attributes.
. 2016-02-03 15:47:18.785 Script: Failed
> 2016-02-03 15:47:19.347 Script: exit
. 2016-02-03 15:47:19.347 Script: Exit code: 1
. 2016-02-03 15:47:19.347 Closing connection.
. 2016-02-03 15:47:19.347 Sending special code: 12
I have amended my script
#transferoptions
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.FileMask = "*.*"
$transferOptions.FilePermissions = $Null # This is default
$transferOptions.PreserveTimestamp = $False
      
# Upload files, collect results
$transferResult = $session.PutFiles(($localPath + "*.*"), ($remotePath + "*.*"), $False, $transferOptions)
Now it works as expected.

Thank you for your time.

Reply with quote

Advertisement

You can post new topics in this forum