private static string GetFtpMethod(FtpClientMethod method) { switch (method) { case FtpClientMethod.AppendFile: return(WebRequestMethods.Ftp.AppendFile); case FtpClientMethod.DeleteFile: return(WebRequestMethods.Ftp.DeleteFile); case FtpClientMethod.DownloadFile: return(WebRequestMethods.Ftp.DownloadFile); case FtpClientMethod.GetDateTimestamp: return(WebRequestMethods.Ftp.GetDateTimestamp); case FtpClientMethod.GetFileSize: return(WebRequestMethods.Ftp.GetFileSize); case FtpClientMethod.ListDirectory: return(WebRequestMethods.Ftp.ListDirectory); case FtpClientMethod.ListDirectoryDetails: return(WebRequestMethods.Ftp.ListDirectoryDetails); case FtpClientMethod.MakeDirectory: return(WebRequestMethods.Ftp.MakeDirectory); case FtpClientMethod.PrintWorkingDirectory: return(WebRequestMethods.Ftp.PrintWorkingDirectory); case FtpClientMethod.RemoveDirectory: return(WebRequestMethods.Ftp.RemoveDirectory); case FtpClientMethod.Rename: return(WebRequestMethods.Ftp.Rename); case FtpClientMethod.UploadFile: return(WebRequestMethods.Ftp.UploadFile); default: return(WebRequestMethods.Ftp.UploadFileWithUniqueName); } }
public static FtpWebResponse Create(string ftpDirectory, string user, string password, string fileName, FtpClientMethod method) { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpDirectory + fileName); request.Method = GetFtpMethod(method); request.Credentials = new NetworkCredential(user, password); using (FtpWebResponse response = (FtpWebResponse)request.GetResponse()) { return(response); } }