我需要知道一种通过 SFTP 连接到 FTP 站点的方法。我正在使用 SharpSSH,但找不到执行该程序的示例。
目前,我已经下载了 SharpSSH .DLL 文件并添加为引用。现在我需要编写可以连接的代码,并从 FTP 服务器上传/下载文件。
我该怎么做?帮助。
更新
代码:
//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");
以上代码在Main方法中。
然后;
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
