Post a reply

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

Nebsorg

Thanks for the information ! I'll try this !

Edit : I made the change, it's works perfectly ! Thanks for the answer !
martin

Re: PowerShell - directory with brackets in name are skiped without triggering error

The remotePath argument of Session.GetFiles is a file mask, not a filename.
See https://winscp.net/eng/docs/library_session_getfiles

The brackets have a special meaning in the filemask.

If you need to use a literal file name, you have to escape it by passing the name though RemotePath.EscapeFileMask
https://winscp.net/eng/docs/library_wildcard
https://winscp.net/eng/docs/library_remotepath_escapefilemask
Nebsorg

PowerShell - directory with brackets in name are skiped without triggering error

Hello,

I use a powershell script to download automatically files from several directories from a remote debian server (SFTP).

In the remote directory, I can have file directly, or sub directories with files. In the second case, I want to kept the directory structure once downloaded.

I use getFiles(remotePath, localPath) to retrieve remote content one by one (I have to make somes tests on the remote content, all of them are not to download), without paying attention if remote content is a file or a directory. WinSCP download both very well and kept the structure.

It's works very well most of the time, but I discover yesterday than if the remotePath string is a directory with a [ inside of the name, the download fail without error.
Downloadresult.issuccess is true, but the direcotry haven't been downloaded ...

I force UTF8 with $sessionOptions.AddRawSettings("Utf","1"), but it doesn't change anything.

I also update my winSCP to last version, but it still fail.
For information, it seem to have a problem with the last package, I got the following error message with this package :
The version of Sync\Bin\WinSCP.exe (5.7.6.0) does not match version of this assembly Sync\Bin\WinSCPnet.dll (5.5.6.0). You can disable this check using Session.DisableVersionCheck (not recommended).
So I disable the check with $session.DisableVersionCheck = "true"

How should I manage the directory name with brackets ?

Thanks for your help,

Ben