Skip to content

Instantly share code, notes, and snippets.

@jcere
Created June 11, 2016 15:57
Show Gist options
  • Save jcere/f4b1156a4cb0de5d920328bc5aa777bc to your computer and use it in GitHub Desktop.
Save jcere/f4b1156a4cb0de5d920328bc5aa777bc to your computer and use it in GitHub Desktop.
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();
}
@jcere
Copy link
Author

jcere commented Jun 11, 2016

A quickie method for an ftp request and write to local file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment