Topic "Session.Getfiles when removal set to $true"

Author Message
Alcasczar
[View user's profile]

Joined: 2016-07-30
Posts: 7
Location: NY
Using Powershell 3.0
Using .NET Assembly 5.9

Any ideas why after the script process $Session.getfiles($remotepath, $localpath, $true, $transferOptions)

it's trying to delete the directory? I had thought it would only do this for "files" not directories. Is there anyway to only delete files after transfer and leave directory structure on the remote side? I looked at Session.SyncronizeDirectory method but that appears to put me in the same boat, maybe

Here's just a clip of the code. It works fine on another sftp server as I expect (doesn't try to delete the directory)

Code:

 $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
        $transferOptions.ResumeSupport.State = [WinSCP.TransferResumeSupportState]::Off
        $transferOptions.FileMask = "*.*|.no_delete,*.part,*.tmp"
             
         
        $transferResult = $session.GetFiles($remotePath, $localPath, $True, $transferOptions)
             
     
        $transferResult.Check()


VERBOSE: Error: Error deleting file '/test/script/file'.
Permission denied.
Error code: 3
Error message from server (en-US): Permission denied


I also looked at batch mode emulation, but not sure how to change the default from abort mode to continue, this may help me workaround it for now.

Thanks for the assistance
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Probably because the $remotePath is /test/script/file and not correct /test/script/file/*
Alcasczar
[View user's profile]

Joined: 2016-07-30
Posts: 7
Location: NY
martin wrote:
Probably because the $remotePath is /test/script/file and not correct /test/script/file/*


Thank you Martin.

Actually it was set like this

$remotePath = '/test/script/files/'

If I set the variable to

$remotePath = '/test/script/files/*'

When calling getfiles($remotePath,$localPath,$true,$tranferOptions) there's an error , I guess it doesn't like the "*" at the end when it's part of the variable? Should it be escaped perhaps?
Alcasczar
[View user's profile]

Joined: 2016-07-30
Posts: 7
Location: NY
Is there a method or function that can be used to Continue instead of abort? say for example I'm downloading in batch and use (Powershell)

$TransferResult.Check()

I'd like to keep going for every file and just log those that don't.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Alcasczar wrote:
If I set the variable to

$remotePath = '/test/script/files/*'

When calling getfiles($remotePath,$localPath,$true,$tranferOptions) there's an error , I guess it doesn't like the "*" at the end when it's part of the variable? Should it be escaped perhaps?

That should not be a problem. Show us a session log file.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24530
Location: Prague, Czechia
Alcasczar wrote:
Is there a method or function that can be used to Continue instead of abort? say for example I'm downloading in batch and use (Powershell)

$TransferResult.Check()

I'd like to keep going for every file and just log those that don't.

See https://winscp.net/eng/docs/library_example_recursive_download_custom_error_handling
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