Renci.SshNet.ScpClient.Download C# (CSharp) Method

Download() public method

Downloads the specified directory from the remote host to local directory.
is null or empty. is null.
public Download ( string directoryName, DirectoryInfo directoryInfo ) : void
directoryName string Remote host directory name.
directoryInfo System.IO.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);
            }
        }

Same methods

ScpClient::Download ( string filename, FileInfo fileInfo ) : void
ScpClient::Download ( string filename, Stream destination ) : void

Usage Example

Beispiel #1
0
        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;
        }
All Usage Examples Of Renci.SshNet.ScpClient::Download