Topic "WinSCP .NET assembly (powershell) putfiles from UNC path only uploads 1 file"

Author Message
Stan.Gobien
[View user's profile]

Joined: 2016-02-03
Posts: 2
Location: Belgium
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:
Code:

#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!
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
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.
Stan.Gobien
[View user's profile]

Joined: 2016-02-03
Posts: 2
Location: Belgium
Thank you for your answer.
because of the session log file i have now seen the error:
Code:
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
Code:

      #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
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License