private async Task <FtpWebResponse> GetFtpResponse(FtpRequestType ftpRequestType) { var request = GetFtpRequest(ftpRequestType); var response = await request.GetResponseAsync(); return(response as FtpWebResponse); }
public static FtpWebRequest Create(string ftpPath, FtpRequestType ftpRequestMethod, IFtpServerConnection ftpServerConnection, IWebProxy proxy) { if (ftpServerConnection == null) { throw new ArgumentNullException(nameof(ftpServerConnection), "отсутствуют параметры подключения к ftp"); } if (string.IsNullOrWhiteSpace(ftpServerConnection.Server)) { throw new ArgumentOutOfRangeException(nameof(ftpServerConnection), "в параметрах подключения к ftp серверу отсутствует адрес сервера"); } var request = Create(ftpPath, ftpRequestMethod, ftpServerConnection.Server, ftpServerConnection.User.ToCredentials(), ftpServerConnection.UsePassive, proxy); return(request); }
public static string ToFtpWebRequestMethod(this FtpRequestType ftpRequestType) { switch (ftpRequestType) { case FtpRequestType.DownloadFile: return(WebRequestMethods.Ftp.DownloadFile); case FtpRequestType.ListDirectory: return(WebRequestMethods.Ftp.ListDirectory); case FtpRequestType.UploadFile: return(WebRequestMethods.Ftp.UploadFile); case FtpRequestType.DeleteFile: return(WebRequestMethods.Ftp.DeleteFile); case FtpRequestType.AppendFile: return(WebRequestMethods.Ftp.AppendFile); case FtpRequestType.GetFileSize: return(WebRequestMethods.Ftp.GetFileSize); case FtpRequestType.UploadFileWithUniqueName: return(WebRequestMethods.Ftp.UploadFileWithUniqueName); case FtpRequestType.MakeDirectory: return(WebRequestMethods.Ftp.MakeDirectory); case FtpRequestType.RemoveDirectory: return(WebRequestMethods.Ftp.RemoveDirectory); case FtpRequestType.ListDirectoryDetails: return(WebRequestMethods.Ftp.ListDirectoryDetails); case FtpRequestType.GetDateTimestamp: return(WebRequestMethods.Ftp.GetDateTimestamp); case FtpRequestType.PrintWorkingDirectory: return(WebRequestMethods.Ftp.PrintWorkingDirectory); case FtpRequestType.Rename: return(WebRequestMethods.Ftp.Rename); default: throw new ArgumentOutOfRangeException(nameof(ftpRequestType), "значение не предусмотрено"); } }
private FtpWebRequest GetFtpRequest(FtpRequestType ftpRequestType) { FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://gildiagrzybiarzy.pl/osu!"); request.Credentials = Credentials.ReturnCredentials(); switch (ftpRequestType) { case FtpRequestType.ListDirectory: { request.Method = WebRequestMethods.Ftp.ListDirectory; } break; case FtpRequestType.Timestamp: request.Method = WebRequestMethods.Ftp.GetDateTimestamp; break; default: break; } return(request); }
public static FtpWebRequest Create(string ftpPath, FtpRequestType ftpRequestMethod, string ftpServerName, ICredentials ftpServerCredentials, bool ftpServerUsePassive, IWebProxy proxy) { if (ftpServerName == null) { throw new ArgumentNullException(nameof(ftpServerName)); } if (string.IsNullOrWhiteSpace(ftpServerName)) { throw new ArgumentOutOfRangeException(nameof(ftpServerName), "в параметрах подключения к ftp серверу отсутствует адрес сервера"); } var url = ToUrl(ftpServerName, ftpPath); var request = (FtpWebRequest)WebRequestFactory.Create(url, ftpRequestMethod.ToFtpWebRequestMethod(), ftpServerCredentials, proxy); request.UsePassive = ftpServerUsePassive; return(request); }
public static FtpWebRequest Create(string ftpPath, FtpRequestType ftpRequestMethod, IFtpServerConnection ftpServerConnection, IProxySettings proxy) { return(Create(ftpPath, ftpRequestMethod, ftpServerConnection, proxy.ToWebProxy())); }