Skip to content

Instantly share code, notes, and snippets.

@rozputnii
Created July 31, 2018 12:18
Show Gist options
  • Select an option

  • Save rozputnii/2bc2ce22eec81fa1199b69a7732cb4fd to your computer and use it in GitHub Desktop.

Select an option

Save rozputnii/2bc2ce22eec81fa1199b69a7732cb4fd to your computer and use it in GitHub Desktop.
var ftpRequest = (FtpWebRequest) WebRequest.Create($"{host}/{path}");
ftpRequest.Credentials = new NetworkCredential(username, password);
/* When in doubt, use these options */
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = true;
/* Specify the Type of FTP Request */
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
var stream = new MemoryStream();
using (cts.Register(ftpRequest.Abort))
using (var ftpResponse = (FtpWebResponse) ftpRequest.GetResponse()) {
using (var ftpStream = ftpResponse.GetResponseStream()) {
ftpStream?.CopyTo(stream);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment