Problem with NET Library 5.9 - Removal parameter $True
Winscp 5.9.0 .NET Library
Script running under Powershell 3.0
Using Sftp
When the below code runs an error appears that it cannot delete file, the file is not a file though. It's an Actual directory.
The remote side stores a hidden file on the server (Linux) called .no_delete (to protect directories from deletion) and as you can see we don't download that as it's in the exclusion FileMask option. The error that is displayed is
The file that's mentioned in the error is not a file it's an actual Directory.
Any assistance is greatly appreciated.
Script running under Powershell 3.0
Using Sftp
When the below code runs an error appears that it cannot delete file, the file is not a file though. It's an Actual directory.
try { $logpath = 'C:\logs\Incoming' if (!(test-path $logpath)) { new-item $logpath -ItemType Directory } # Load WinSCP .NET assembly Add-Type -Path "C:\Winscp\WinSCPnet.dll" $VerbosePreference = 'Continue' $remotePath = '/Test/Incoming/' $localPath = 'C:\Test\Incoming' $HostKey = "ssh-rsa 2048 50:e8:d0:20:ea:45:98:28:7f:4w:59:89:b9:19:49:99" [int]$port = 22 # Setup session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "myserver" PortNumber = $port UserName = "testuser" Password = "Secret" SshHostKeyFingerprint = $HostKey } try { $session = New-Object WinSCP.Session # Connect $session.Open($sessionOptions) # Download files $transferOptions = New-Object WinSCP.TransferOptions $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off $transferOptions.FileMask = "*.*|.no_delete,*.tmp,*.part" $transferResult = $session.GetFiles($remotePath, $localPath, $True, $transferOptions) $transferResult.Check() foreach ($transfer in $transferResult.Transfers) { $Filename = $transfer.FileName Write-verbose ("Download of {0} succeeded" -f $transfer.FileName) } # Disconnect, clean up $session.Dispose() Exit 0 } catch [exception] { Write-Verbose ("Error: {0}" -f $_.Exception.Message) Exit 1 } } catch { write-verbose " F A T A L -- E R R O R" add-log $logpath -data $_ }
The remote side stores a hidden file on the server (Linux) called .no_delete (to protect directories from deletion) and as you can see we don't download that as it's in the exclusion FileMask option. The error that is displayed is
[8/3/2016 2:09 PM] An Error has occurred: : Error deleting file '/Test/Incoming/AccessPoint'. General failure (server should provide error description). Error code: 4 Error message from server (en-US): Directory is not empty Common reasons for the Error code 4 are: - Renaming a file to a name of already existing file. - Creating a directory that already exists. - Moving a remote file to a different filesystem (HDD). - Uploading a file to a full filesystem (HDD). - Exceeding a user disk quota.
The file that's mentioned in the error is not a file it's an actual Directory.
Any assistance is greatly appreciated.