使用SFTP从FTP站点上载下载文件 [英] Upload Download files from FTP site using SFTP
问题描述
我需要知道一种通过SFTP连接到FTP站点的方法.我正在使用SharpSSH
,但找不到执行该程序的示例.
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.
现在,我已经下载了SharpSSH
.DLL
文件并添加为参考.现在,我需要编写可以连接的代码,并从FTP服务器上载/下载文件.
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.
我该怎么做?帮助.
更新
代码:
//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方法中.
The above code is in the Main Method.
然后;
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();
}
}
}
推荐答案
到目前为止,您做了什么?
What have you done as of right now?
我们不能直接为您提供有关如何上传文件"的答案....
We can't just give you a straight answer on 'how to upload files'....
这是一个教程: http://saravanandorai.blogspot .com/2012/01/sftp-and-file-upload-in-sftp-using-c.html
这篇关于使用SFTP从FTP站点上载下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!