Thursday, 12 May 2016

How to upload File to Secured FTP ( SFTP ) in C#

Upload File from Local Machine to SFTP Server in C#

The following C# code will upload a file from local machine to SFTP server.

string _ftpURL = "testsftp.com"; //Host URL or address of the SFTP server
string _UserName = "admin";      //User Name of the SFTP server
string _Password = "admin123";   //Password of the SFTP server
int _Port = 22;                  //Port No of the SFTP server (if any)
string _ftpDirectory = "Receipts"; //The directory in SFTP server where the files will be uploaded
string LocalDirectory = "D:\\FilePuller"; //Local directory from where the files will be uploaded
string FileName = "test.txt";    //File name, which one will be uploaded

Sftp oSftp = new Sftp(_ftpURL, _UserName, _Password);
oSftp.Connect(_Port);
oSftp.Put(LocalDirectory + "/" + FileName, _ftpDirectory + "/" + FileName);
oSftp.Close();
 
tamir.sharpssh.dll can be downloaded from below link.


https://sourceforge.net/projects/sharpssh/?source=typ_redirect

No comments:

Post a Comment