Created
June 11, 2016 15:57
-
-
Save jcere/f4b1156a4cb0de5d920328bc5aa777bc to your computer and use it in GitHub Desktop.
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
public void FtpRequest(string ftpPath, string destPath) | |
{ | |
// Get the object used to communicate with the server. | |
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpPath); | |
request.Method = WebRequestMethods.Ftp.DownloadFile; | |
// This example assumes the FTP site uses anonymous logon. | |
request.Credentials = new NetworkCredential(userName, passWord); | |
FtpWebResponse response = (FtpWebResponse)request.GetResponse(); | |
Stream responseStream = response.GetResponseStream(); | |
StreamReader reader = new StreamReader(responseStream); | |
try | |
{ | |
WriteResponseToFile(destPath, response, responseStream); | |
} | |
catch (Exception ex) | |
{ | |
log.Debug(ex); | |
} | |
reader.Close(); | |
responseStream.Close(); | |
response.Close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A quickie method for an ftp request and write to local file