Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more:
How to download files from SFTP server using C#
Posted

You can use for this purpose ComponentPro[^]. The following code demonstrates that:

C#
using ComponentPro.Net;
using ComponentPro.IO;

...

// Create a new instance.
Sftp client = new Sftp();

// Connect to the SFTP server.
client.Connect("myserver");

// Authenticate.
client.Authenticate("userName", "password");

// ...

// Get all directories, subdirectories, and files from remote folder '/myfolder' to 'c:\myfolder'.
client.DownloadFiles("/myfolder", "c:\\myfolder");

// Get all directories, subdirectories, and files that match the specified search pattern from remote folder '/myfolder2' to 'c:\myfolder2'.
client.DownloadFiles("/myfolder2", "c:\\myfolder2", "*.cs");

// or you can simply put wildcard masks in the source path, our component will automatically parse it.
// download all *.css files from remote folder '/myfolder2' to local folder 'c:\myfolder2'.
client.DownloadFiles("/myfolder2/*.css", "c:\\myfolder2");

// Download *.cs and *.vb files from remote folder '/myfolder2' to local folder 'c:\myfolder2'.
client.DownloadFiles("/myfolder2/*.cs;*.vb", "c:\\myfolder2");

// Get files in the folder '/myfolder2' only.
TransferOptions opt = new TransferOptions(true, RecursionMode.None, false, (SearchCondition)null, FileExistsResolveAction.Overwrite, SymlinksResolveAction.Skip);
client.DownloadFiles("/myfolder2", "c:\\myfolder2", opt);

// ...

// Disconnect.
client.Disconnect();



For more examples see:
http://www.componentpro.com/sftp/[^]
 
Share this answer
 
v4
Check this link, may help you

http://www.sftp-net.com/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900