public Download ( string directoryName, |
||
directoryName | string | Remote host directory name. |
directoryInfo | Local directory information. | |
return | void |
public void Download(string directoryName, DirectoryInfo directoryInfo)
{
if (string.IsNullOrEmpty(directoryName))
throw new ArgumentException("directoryName");
if (directoryInfo == null)
throw new ArgumentNullException("directoryInfo");
using (var input = ServiceFactory.CreatePipeStream())
using (var channel = Session.CreateChannelSession())
{
channel.DataReceived += (sender, e) => input.Write(e.Data, 0, e.Data.Length);
channel.Open();
// Send channel command request
channel.SendExecRequest(string.Format("scp -prf \"{0}\"", directoryName));
SendConfirmation(channel); // Send reply
InternalDownload(channel, input, directoryInfo);
}
}
private bool download() { folderBrowserDialog.Description = "Choose Where To Download"; if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (listView1.SelectedItems.Count > 0) { try { listView1.Enabled = false; ScpClient scpClient = new ScpClient(this.sftpClient.ConnectionInfo); scpClient.Connect(); foreach (ListViewItem lvi in listView1.SelectedItems) { SftpFile sf = (SftpFile)(lvi.Tag); if (sf.IsDirectory) { scpClient.Download(sf.FullName, new System.IO.DirectoryInfo(folderBrowserDialog.SelectedPath).CreateSubdirectory(sf.Name)); } else { scpClient.Download(sf.FullName, new System.IO.FileInfo(folderBrowserDialog.SelectedPath + "\\" + sf.Name)); } } scpClient.Disconnect(); } catch (Exception ex) { } finally { listView1.Enabled = true; } } } return true; }