WinSCP .NET assembly Skip failures

264 views Asked by At

I'm trying to download a complete folder via WinSCP. However there can be files that I do not have permission to download in them.

/www/
/www/file1 <-- No permission
/www/file2 <-- Permission
/www/ ..
/www/file999
/www/folder1/
/www/folder1/file28328
/www/folder1/file342423 <-- No permission
etc...

There's a few thousand files, so I don't really want to blacklist them. I'm downloading them using the following command:

using(var session = new Session())
{
  session.Open(options);
  session.GetFiles("/www", "C:/backup");
}

This then fails on file1, and does not continue. Is there a way (preferably an option) where I can just skip these files? I just want it to download everything it can.

1

There are 1 answers

0
Martin Prikryl On BEST ANSWER

There's no such option (yet).

But you can do it to "manually" by recursing the directory structure, downloading the files one by one, handling the errors as you like.

There's an example implementation available in C# and Powershell:
Recursively download directory tree with custom error handling.