使用SFTP FTP站点上传下载文件(Upload Download files from FTP

2019-10-16 19:48发布

我需要知道一种方法,通过SFTP连接到FTP站点。 我使用SharpSSH ,我无法找到一个例子做方案。

现在,我已经下载了SharpSSH .DLL文件,并添加引用。 现在我需要从FTP服务器写在那里我可以连接代码,并上传/下载文件。

我怎样才能做到这一点 ? 救命。

UPDATE

代码:

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

上面的代码中的主要方法。

然后 ;

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

Answer 1:

你有什么作为的,现在做了什么?

我们不能只给你'如何上传文件的一个直接的答案....

这里是一个教程: http://saravanandorai.blogspot.com/2012/01/sftp-and-file-upload-in-sftp-using-c.html



Answer 2:

我认为FtpAddress参数应该是没有ftphttp ,所以请尝试以下操作:

 FileUploadUsingSftp("Some-sftp-site.com", "username", 
                     "password", @"D:\", @"name.txt");


文章来源: Upload Download files from FTP site using SFTP