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

Download() public method

Downloads the specified file from the remote host to local file.
is null. is null or empty.
public Download ( string filename, FileInfo fileInfo ) : void
filename string Remote host file name.
fileInfo System.IO.FileInfo Local file information.
return void
        public void Download(string filename, FileInfo fileInfo)
        {
            if (string.IsNullOrEmpty(filename))
                throw new ArgumentException("filename");
            if (fileInfo == null)
                throw new ArgumentNullException("fileInfo");

            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 -pf \"{0}\"", filename));
                SendConfirmation(channel); //  Send reply

                InternalDownload(channel, input, fileInfo);
            }
        }

Same methods

ScpClient::Download ( string directoryName, DirectoryInfo directoryInfo ) : 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