Upload Download files from FTP site using SFTP

 ̄綄美尐妖づ 提交于 2019-12-11 05:44:49

问题


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

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();
                }
            }
        }

回答1:


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




回答2:


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");


来源:https://stackoverflow.com/questions/10899324/upload-download-files-from-ftp-site-using-sftp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!