Topic "GetFiles Method Has Started Attempting to Delete Remote Directory"

Author Message
tmiddleton
[View user's profile]

Joined: 2015-10-16
Posts: 3
Location: Tulsa
We started getting permission denied exceptions out of nowhere the other night. It's coming from the remote server when we try to remove the remote files after downloading. We are using GetFiles method with the Remove flag set to true. There were no code changes on our end that I know of and at the time of first occurance we were running 5.7.1. I found a similar bug report and upgraded to 5.7.5 but the behavior has not changed. Is there a way to disable this behavior? I only want the files removed not the folder.

I apologize in advance if this this is already covered somewhere but I could find no other reference to this behavior nor any property I could set to turn it off.

I've attached the relevant portion of the log.
Log.txt (4.23 KB) [Download]

Description: (none)

Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
What "this behaviour"?

Show us your code and the session log file (Session.SessionLogPath).
tmiddleton
[View user's profile]

Joined: 2015-10-16
Posts: 3
Location: Tulsa
Hello, thank you for responding so quickly!

The behavior or action I want it to take is to delete the remote files that were successfully downloaded but not the remote directory. The login being used doesn't have sufficient privileges to remove a directory so the permission denied exception is being returned and causing the script to terminate with a failure code.

I've included the script below. The log I attached in the fist post is from the session log file. I'll get you a more complete version if needed asap.


Code:
$CurrentDir = Split-Path ((Get-Variable MyInvocation -Scope 0).Value).MyCommand.Path
$ProcessingFolder = "\\local\path\"

try
{
    Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
   
    $sessionOptions = New-Object WinSCP.SessionOptions
    $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
    $sessionOptions.HostName = ""
    $sessionOptions.UserName = ""
    $sessionOptions.Password =
    $sessionOptions.SshHostKeyFingerprint = ""
    $sessionOptions.Timeout = New-TimeSpan -Seconds 30

    $session = New-Object WinSCP.Session
    $session.SessionLogPath = "$CurrentDir\WinSCP.log"

    $session.Open($sessionOptions)
 
    $transferOptions = New-Object WinSCP.TransferOptions
    $transferOptions.TransferMode = [WinSCP.TransferMode]::Automatic
    $transferOptions.FilePermissions = $null
    $transferOptions.PreserveTimestamp = $False

    $transferResult = $session.GetFiles("/remote/path/", $ProcessingFolder, $True, $transferOptions)
   
    $transferResult.Check()
}
catch [Exception]
{
    ...Send Email...
    exit 1
}
finally
{
    # Disconnect, clean up
    $session.Dispose()
}
tmiddleton
[View user's profile]

Joined: 2015-10-16
Posts: 3
Location: Tulsa
Attaching Session log file...
Log (2).txt (11.71 KB) Private file

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
tmiddleton wrote:
The behavior or action I want it to take is to delete the remote files that were successfully downloaded but not the remote directory. The login being used doesn't have sufficient privileges to remove a directory so the permission denied exception is being returned and causing the script to terminate with a failure code.

So download (and delete) the files only, not the parent directory:

$transferResult = $session.GetFiles("/remote/path/*", $ProcessingFolder, $True, $transferOptions)
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