C# Renci.SshNet Download Files in a Directory

//Example Renci.SSHNet Simple Usage to download files in a directory
string BackupFolder="C:\\backup";
SftpClient sftp = null;
sftp = new SftpClient(Host, Port, Username, upassword);

foreach (Renci.SshNet.Sftp.SftpFile ftpfile in sftp.ListDirectory("."))
{
	using (FileStream fs = new FileStream(BackupFolder + "\\" + ftpfile.Name, FileMode.Create))
	{
		sftp.DownloadFile(ftpfile.FullName, fs);
	}

}

Resources:
http://sshnet.codeplex.com/

 

 

2 thoughts on “C# Renci.SshNet Download Files in a Directory

  1. Seamus O Connor

    foreach (Renci.SshNet.Sftp.SftpFile ftpfile in sftp.ListDirectory(“.”))

    This does not work as the string needs to be a valid URI or am I missing something?

Leave a Reply

%d bloggers like this: