Updated on Kisan Patel
To download files using the File Transfer Protocol (FTP), you need to use the System.Net.FtpWebRequest
class.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://example.com/bootstrap-theme.css"); request.Credentials = new NetworkCredential("username", "password"); using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) { Stream data = response.GetResponseStream(); string targetPath = @"C:\bootstrap-theme.css"; //Save file to C drive if (File.Exists(targetPath)) File.Delete(targetPath); byte[] byteBuffer = new byte[4096]; using (FileStream output = new FileStream(targetPath, FileMode.CreateNew)) { int bytesRead = 0; do { bytesRead = data.Read(byteBuffer, 0, byteBuffer.Length); if (bytesRead > 0) { output.Write(byteBuffer, 0, bytesRead); } } while (bytesRead > 0); } }