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: Session.GetFiles not able to delete remote files

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

To generate the session 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.


Btw, you are not checking results of session.GetFiles – The indentation of that code is confusing.
teyers@paragonhealthcare.com

Session.GetFiles not able to delete remote files

I am using the following script to push and pull files from several sites without any issues. As part of the script it is set to remove the files once they have been pushed or pulled successfully. I have one site that is not allowing the script to remove the remote files after a successful GetFiles. It appears to be something on the providers side, but I am not sure what to tell them or to get a workaround on my side. Any clues as to what's going on?

The only error message I see is the following:
Transfers Failures                                                                                                                                                                            

--------- --------                                                                                                                                                                           
{}        {WinSCP.SessionRemoteException: Error deleting file '/out/.working'....

Script:
try
{
    $session = New-Object WinSCP.Session
 
    $OUTLocalPath = "\\SERVERNAME\OUTBOUND\*"
    $OUTRemotePath = "/in/"
 
    $INLocalPath = "\\SERVERNAME\INBOUND\"
    $INRemotePath = "./out/*"
 
    $ArhivePath = "\\\SERVERNAME\Archive\"
 
    # Make an Arvhive copy
 
    Copy-Item -Path $OUTLocalPath -Destination $ArhivePath -Recurse
     
    try
    {
        # Connect
        $session.Open($sessionOptions)
 
        # Upload files
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
 
        $transferResult =
            $session.PutFiles($OUTLocalPath,$OUTRemotePath , $True, $transferOptions)
            $session.GetFiles($INRemotePath,$INLocalPath,$True, $transferOptions)
 
        # Throw on any error
        $transferResult.Check()
 
        # Print results
        foreach ($transfer in $transferResult.Transfers)
        {
            Write-Host "Upload of $($transfer.FileName) succeeded"
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    #exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    #exit 1
}