[英]Upload Download files from FTP site using SFTP
我需要知道通过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();
}
}
}
你现在做了什么?
我们不能只给你一个关于'如何上传文件'的直接答案....
这是一个教程: http : //saravanandorai.blogspot.com/2012/01/sftp-and-file-upload-in-sftp-using-c.html
我认为FtpAddress
参数应该没有ftp
或http
,所以请尝试以下方法:
FileUploadUsingSftp("Some-sftp-site.com", "username",
"password", @"D:\", @"name.txt");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.