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

javier.rsotolongo

WinSCP .NET does not support passing literal file names without mask interpretation

There's no API in WinSCP .NET assembly to pass a literal file name, without interpreting it as a file mask.

Is there a way to copy a single file whose name includes wildcard characters (e.g., [Hospital1]_0001.txt) without WinSCP listing the entire directory?

session.GetFileToDirectory("/IDEData/[Hospital1]_0001.txt", @"C:\IdeData\", true, null);


WinSCP treats [ and ] as wildcard characters, so instead of copying the file directly, it attempts to resolve the pattern and ends up listing the entire directory. The problem is that this folder contains over one million files, so the directory listing takes around 40 minutes and triggers a timeout exception—even though I only need to copy a single file.

This does not happen with files like Test.txt, but all required files in my case include square brackets. I also tried RemotePath.EscapeFileMask(fileName), but it didn't solve my issue.

I tried
session.GetFiles(session.EscapeFileMask("/var/pathTo/[Hospital1]_001.txt"), @"C:\somewhere\*").Check();
but it didn't work either.

See:
https://stackoverflow.com/questions/79845134/how-can-i-copy-a-single-file-whose-name-includes-wildcard-characters-without-lis#comment140902408_79845134