FTP in .Net

Doing FTP in .Net is not as hard as you may imagine. There is a very simple way and a bit advanced way. Simple way is using System.Net.WebClient class    and its UploadFile method. Advanced way includes using System.Net.FtpWebRequest and System.Net.FtpWebResponse classes. Using them you can do ordinary FTP operations like ListDirectory, UploadFile, DeleteFile, etc. For an example see following code. More information is available from here.

public void DeleteFile(string remotePath)
    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(remotePath);
    request.Credentials = new NetworkCredential("user name", "password");
    request.Method = WebRequestMethods.Ftp.DeleteFile;

    FtpWebResponse response = (FtpWebResponse)request.GetResponse();


دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *