Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SFTP from .NET
Message
From
01/12/2016 14:58:17
 
 
To
30/11/2016 16:26:34
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
01644158
Message ID:
01644206
Views:
48
>Does anyone have any suggestions for an SFTP client for .NET?
>
>I've seen a few, but would appreciated any recommendations.

Here's the one I use: https://github.com/sshnet/SSH.NET

Code sample (I used this code to download a file from the FTP server and store it on my local machine):
   class Program
    {
        static void Main(string[] args)
        {
            // http://www.csidata.com/?page_id=2828
            // http://stackoverflow.com/questions/23703040/download-files-from-sftp-with-ssh-net-library

            //http://www.jokecamp.com/blog/connecting-to-sftp-with-key-file-and-password-using-ssh-net/
            string keyFile = @"c:/path-to-your-ppk-file/blah_private.ppk_openssh";
            string passPhrase = "your-passphrase";
            PrivateKeyFile privateKeyFile = new PrivateKeyFile(keyFile, passPhrase);

            string host = @"123.123.123.123";
            int port = 22;
            string username = "root-user-name";
            string remoteFilename = @"/root/path-to-file/filename-to-download.ext";
            
            //DateTime in Filename from here: http://www.dotnetperls.com/filename-datetime

            string localFilename = string.Format("Development-{0:yyyy-MM-dd_hh-mm-ss-tt}.ext",  DateTime.Now);
            localFilename = @"c:\users\Billy\download-path\" + localFilename;

            //using (var sftp = new SftpClient(host, port, username, password))

            using (var sftp = new SftpClient(host, port, username, privateKeyFile))
            {
                sftp.Connect();

                using (var file = File.OpenWrite(localFilename))
                {
                    sftp.DownloadFile(remoteFilename, file);
                }

                sftp.Disconnect();
            }

        }
    }
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform