我需要知道一种方法,通过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();
}
}
}