Upload Download files from FTP site using SFTP

2019-07-23 12:30发布

I need to know a way to connect to a FTP site through SFTP. I am using SharpSSH and i am unable to find an example to do the program.

For now, i have downloaded the SharpSSH .DLL files and added as references. Now i need to write the code where i could connect, and upload/download files from the FTP server.

How can i do this ? Help.

UPDATE enter image description here

Code :

//ip of the local machine and the username and password along with the file to be uploaded via SFTP.
 FileUploadUsingSftp("http://Some-sftp-site.com", "username", "password", @"D:\", @"name.txt");

The above code is in the Main Method.

Then ;

private static void FileUploadUsingSftp(string FtpAddress, string FtpUserName, string FtpPassword, string FilePath, string FileName)
        {
            Sftp sftp = null;
            try
            {
                // Create instance for Sftp to upload given files using given credentials
                sftp = new Sftp(FtpAddress, FtpUserName, FtpPassword);

                // Connect Sftp
                sftp.Connect();

                // Upload a file
                sftp.Put(FilePath + FileName);

                // Close the Sftp connection
                sftp.Close();
            }
            finally
            {
                if (sftp != null)
                {
                    sftp.Close();
                }
            }
        }

2条回答
Juvenile、少年°
2楼-- · 2019-07-23 13:24

I think the FtpAddress parameter should be without ftp or http, so try the following:

 FileUploadUsingSftp("Some-sftp-site.com", "username", 
                     "password", @"D:\", @"name.txt");
查看更多
时光不老,我们不散
3楼-- · 2019-07-23 13:29

What have you done as of right now?

We can't just give you a straight answer on 'how to upload files'....

Here is a tutorial: http://saravanandorai.blogspot.com/2012/01/sftp-and-file-upload-in-sftp-using-c.html

查看更多
登录 后发表回答