Created
July 31, 2012 19:48
-
-
Save kristopherjohnson/3219937 to your computer and use it in GitHub Desktop.
C# snippet: Download a file via FTP, returning response as a String
This file contains 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
static String FtpDownloadFileText(String fileURL, String userName, String password) | |
{ | |
var request = WebRequest.Create(fileURL); | |
request.Method = WebRequestMethods.Ftp.DownloadFile; | |
request.Credentials = new NetworkCredential(userName, password); | |
var response = (FtpWebResponse) request.GetResponse(); | |
var responseStream = response.GetResponseStream(); | |
var reader = new StreamReader(responseStream); | |
var responseText = reader.ReadToEnd(); | |
reader.Close(); | |
response.Close(); | |
return responseText; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment