Работа с FTP из C# – легко!

Нашел на одном из западных блогов очень удобную библиотеку для работы с фтп.

Чтоб загрузить файл на свой сервер достаточно написать пару строк:

using BytesRoad.Net.Ftp;

… 

string FtpServer = “my.server.ru”;

string Username = “username”;

string Password = “password”;

string RemotePath = “\\folderonserver/”;

 

public void UploadFile(string LocalFile)

{

 // get instance of the FtpClient

 FtpClient client = new FtpClient();

 

 // use passive mode

 client.PassiveMode = true;

 

 client.Connect(Timeout, FtpServer, 21);

 client.Login(Timeout, Username, Password);

 

 // build the target file path

 string target = System.IO.Path.Combine(RemotePath,

 System.IO.Path.GetFileName(LocalFile)).Replace(“\\”, “/”);

 

 // synchronously upload the file

 client.PutFile(Timeout, target, LocalFile);

 

 //Disconnect

 client.Disconnect(Timeout);

}

Обратите внимание, что используется passive mode

Библиотека распространяется по лицензии GPL, то есть бесплатно. Скачать можно отсюда.