Created
July 31, 2018 12:18
-
-
Save rozputnii/2bc2ce22eec81fa1199b69a7732cb4fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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