Quantcast
Channel: sshnet Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1729

New Post: Urgent: ScpClient - How to download entire remote directory to local directory

$
0
0
Hello All,

I am trying to download all files and sub-folder from a remote directory to local directory. For this I am using "ScpClient" and method name is "Download". Based on documentation (if I have not read it wrongly) it says "Downloads the specified directory from the remote host to local directory." But the same is not happening for me.

Below is the code, please let me know if I am doing any mistake. Any pointers/help are greatly appreciated (its urgent for a go-live project).
            public void TestSynchronisation(string hostaddress, string username, string password, string hostfolderpath, string destinationPath)
        {
            using (var sftp = new ScpClient(hostaddress, username, password))
            {
                sftp.Connect();

                DirectoryInfo dirInfo = new DirectoryInfo(destinationPath);
                sftp.Downloading += sftp_Downloading;
                sftp.ErrorOccurred += sftp_ErrorOccurred;
                sftp.Download(hostfolderpath, dirInfo);            }
        }

        void sftp_ErrorOccurred(object sender, Renci.SshNet.Common.ExceptionEventArgs e)
        {
            Console.Write(e.Exception.Message.ToString());
            Console.ReadLine();
        }

        void sftp_Downloading(object sender, Renci.SshNet.Common.ScpDownloadEventArgs e)
        {
            Console.WriteLine(e.Filename.ToString());
            Console.WriteLine(e.Downloaded.ToString());
        }    
PS: It does not throw any error either shows any progress via downloading event.

Regards,
Chirag

Viewing all articles
Browse latest Browse all 1729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>