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

Author Message
[View user's profile]

Joined: 2015-01-16
Posts: 4

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 ( does not match version of this assembly Sync\Bin\WinSCPnet.dll ( 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,

[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24736
Location: Prague, Czechia
The remotePath argument of Session.GetFiles is a file mask, not a filename.

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 Session.EscapeFileMask
[View user's profile]

Joined: 2015-01-16
Posts: 4
Thanks for the information ! I'll try this !

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

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!


About donations

$9   $19   $49   $99

About donations


WinSCP Privacy Policy

WinSCP License