3

So, basically I am trying to download only one file from the entire folder on my server.

Folder "domain" contains those files right now:

File1.txt
File2.txt
File3.txt

So, as I can see in WinSCP docs if I want to download only one file I still should use Session.GetFiles() (method docs) with full path to file. Okay, but I can't understand what's my problem, because it's not working.

session.GetFiles("/domains/domain/File1.txt", Directory.GetCurrentDirectory());

However if I change the remote path to whole directory, not a single file I need it works great, but I don't need all three .txt files.

session.GetFiles("/domains/domain/", Directory.GetCurrentDirectory());

1 Answer 1

4

As the documentation for the localPath argument of Session.GetFiles says, the argument is:

Full path to download the file to.

So it should be:

var localPath = Path.Combine(Directory.GetCurrentDirectory(), "File1.txt");
session.GetFiles("/domains/domain/File1.txt", localPath);

Alternatively, you can simplify the code by using Session.GetFileToDirectory, which does what you have expected from Session.GetFiles:

session.GetFileToDirectory(
    "/domains/domain/File1.txt", Directory.GetCurrentDirectory());

See also https://winscp.net/eng/docs/faq_script_vs_gui#inputs

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.