我需要知道一種通過SFTP連接到FTP站點的方法。我正在使用SharpSSH
,我無法找到執行該程序的示例。上傳使用SFTP從FTP站點下載文件
現在,我已經下載了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();
}
}
}
它是FTP站點,還是SFTP站點或FTPS站點?他們是3種不同的東西。 – Joe
這是一個'SFTP'網站 – Illep
這似乎是DNS解析的問題。您的計算機能否成功將您的SFTP服務器的名稱解析爲IP地址? – Joe