internal Stream Request(string path, FtpMethod method, Stream requestStream) { var request = GetRequest(path, typeof(WebRequestMethods.Ftp).GetField(method.ToString()).GetValue(null).ToString()); if (requestStream != null) { Stream stream = request.GetRequestStream(); requestStream.CopyTo(stream); stream.Close(); } return(GetResponse(request)); }
// https://msdn.microsoft.com/en-us/library/ms229716(v=vs.110).aspx public static FtpWebRequest GetFtpWebRequest(string path, string ftpUser, string ftpPassword, FtpMethod method, int timeout = 60000) { FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(new Uri(path)); ftp.Timeout = timeout; ftp.Method = method.GetDescription(); ftp.UseBinary = true; ftp.Proxy = null; if (string.IsNullOrEmpty(ftpUser) || string.IsNullOrEmpty(ftpPassword)) { throw new Exception("Missing credentials."); } ftp.Credentials = new NetworkCredential(ftpUser, ftpPassword); return(ftp); }