Session.Getfiles when removal set to $true

Advertisement

Alcasczar
Joined:
Posts:
7
Location:
NY

Session.Getfiles when removal set to $true

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)

 $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

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
27,253
Location:
Prague, Czechia

Re: Session.Getfiles when removal set to $true

Probably because the $remotePath is /test/script/file and not correct /test/script/file/*

Reply with quote

Alcasczar
Joined:
Posts:
7
Location:
NY

Re: Session.Getfiles when removal set to $true

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?

Reply with quote

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

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
27,253
Location:
Prague, Czechia

Re: Session.Getfiles when removal set to $true

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.

Reply with quote

Advertisement

You can post new topics in this forum