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

Alcasczar

Thank you Martin

I was able to discuss the issue with our FTP admins and they setup the account so it can see the .no_delete file and the script runs perfectly without error now.

Cheers.
martin

Re: Problem with NET Library 5.9 - Removal parameter $True

Your SFTP server does not even return the .no_delete in the listing. So WinSCP is not aware of it. If the file is in the AccessPoint subfolder too, that explains why WinSCP fails deleting the subfolder. Had the SFTP server returned the "hidden" file in the listing (what most SFTP servers would do), WinSCP would skip it as instructed by the exclude mask, and won't try to delete the subfolder.

If you want to move all files form the server, keeping the directory structure, use this script (as you know already):
https://winscp.net/eng/docs/library_example_recursive_download_custom_error_handling
Just add the third remove = true argument to the GetFiles.
Alcasczar

Re: Problem with NET Library 5.9 - Removal parameter $True

martin wrote:

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.


Attached is a session log.


Thanks!!
martin

Re: Problem with NET Library 5.9 - Removal parameter $True

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.
Alcasczar

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.


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.