/// <inheritdoc/> public override Task <IFtpResponse?> Process(FtpCommand command, CancellationToken cancellationToken) { var transferMode = FtpTransferMode.Parse(command.Argument); FtpResponse response; if (transferMode.FileType == FtpFileType.Ascii) { response = new FtpResponse(200, T("ASCII transfer mode active.")); } else if (transferMode.IsBinary) { response = new FtpResponse(200, T("Binary transfer mode active.")); } else { response = new FtpResponse(504, T("Mode {0} not supported.", command.Argument)); } if (response.Code == 200) { var transferModeFeature = Connection.Features.Get <ITransferConfigurationFeature>(); transferModeFeature.TransferMode = transferMode; } return(Task.FromResult <IFtpResponse?>(response)); }
public static HealthCheckContext AddFtp( this HealthCheckContext checkContext, string host, string username, string password, int port, FtpTransferMode mode, string description) { checkContext.Add(host, async() => { try { using (var ftpClient = new FtpClient(new FtpClientConfiguration { Host = host, Username = username, Password = password, Port = port, Mode = (CoreFtp.Enum.FtpTransferMode)mode })) { await ftpClient.LoginAsync().ConfigureAwait(false); } return(HealthCheckResult.Healthy(host)); } catch { return(HealthCheckResult.Unhealthy(host)); } }); return(checkContext); }
/// <inheritdoc/> public override Task <FtpResponse> Process(FtpCommand command, CancellationToken cancellationToken) { var transferMode = FtpTransferMode.Parse(command.Argument); FtpResponse response; if (transferMode.FileType == FtpFileType.Ascii) { response = new FtpResponse(200, "ASCII transfer mode active."); } else if (transferMode.IsBinary) { response = new FtpResponse(200, "Binary transfer mode active."); } else { response = new FtpResponse(504, $"Mode {command.Argument} not supported."); } if (response.Code == 200) { Connection.Data.TransferMode = transferMode; } return(Task.FromResult(response)); }
/// <summary> /// Sets the transfer mode. /// </summary> /// <param name="value">The value.</param> internal void SetTransferMode(FtpTransferMode value) { if (value != Connection.TransferMode) { Expect(SendCommand("TYPE", ((char)value).ToString()), 200); Connection.TransferMode = value; } }
public FtpDataStreamWriter(Stream stream, FtpTransferMode mode) { if (mode != FtpTransferMode.Stream) throw new NotImplementedException(mode + " mode not implemented"); this._stream = stream; this._mode = mode; }
public FtpDataStreamReader(Stream stream, FtpTransferMode mode) { if (mode == FtpTransferMode.Compressed) throw new NotImplementedException("Compressed mode not implemented"); this._stream = stream; this._mode = mode; }
/// FTPサーバーへMODEコマンドを送信します。 /// <summary> /// Send mode command to ftp server. /// FTPサーバーへMODEコマンドを送信します。 /// </summary> /// <param name="mode">転送モード</param> /// <returns></returns> public FtpCommandResult ExecuteMode(FtpTransferMode mode) { switch (mode) { case FtpTransferMode.Stream: return(this.Execute("Mode S")); case FtpTransferMode.Block: return(this.Execute("Mode B")); case FtpTransferMode.Compression: return(this.Execute("Mode C")); default: throw new FtpClientException(); } }
/// <summary> /// Processes the stor. /// </summary> /// <param name="session">The handle.</param> /// <param name="path">The path.</param> /// <param name="mode">The mode.</param> /// <returns></returns> /// <exception cref="IOException"></exception> private static Stream ProcessStor(FtpSession session, FtpPath path, FtpTransferMode mode = FtpTransferMode.Binary) { var stream = OpenDataStream(session, mode, FtpStreamMode.Write); var reply = session.Expect(session.SendCommand("STOR", path.ToString()), 125, 150, 425, 550); if (!reply.Code.IsSuccess) { stream.Abort(); session.ThrowException(reply); return(null); } return(stream.Validated()); }
public override void Process(params string[] args) { client.LoginInfo.transferMode = FtpTransferMode.Parse(args[0]); if (client.LoginInfo.transferMode.FileType == FtpFileType.Ascii) { client.Send(ResultCode.Success.ConvertString("ASCII transfer mode active.")); } else if (client.LoginInfo.transferMode.IsBinary) { client.Send(ResultCode.Success.ConvertString("Binary transfer mode active.")); } else { throw new ArgumentErrorException(); } }
/// <summary> /// Determines the file size of the given file /// </summary> /// <param name="transferMode"></param> /// <param name="secondType"></param> /// <returns></returns> public async Task SetTransferMode(FtpTransferMode transferMode, char secondType = '\0') { EnsureLoggedIn(); Logger?.LogTrace($"[FtpClient] Setting transfer mode {transferMode}, {secondType}"); var response = await ControlStream.SendCommandAsync(new FtpCommandEnvelope { FtpCommand = FtpCommand.TYPE, Data = secondType != '\0' ? $"{(char) transferMode} {secondType}" : $"{(char) transferMode}" }); if (!response.IsSuccess) { throw new FtpException(response.ResponseMessage); } }
/// <summary> /// Determines the file size of the given file /// </summary> /// <param name="transferMode"></param> /// <param name="secondType"></param> /// <returns></returns> public async Task SetTransferMode(FtpTransferMode transferMode, char secondType = '\0') { EnsureLoggedIn(); Logger?.LogDebug($"[FtpClient] Setting transfer mode {transferMode}, {secondType}"); var typeResponse = await SendCommandAsync(new FtpCommandEnvelope { FtpCommand = FtpCommand.TYPE, Data = secondType != '\0' ? $"{(char) transferMode} {secondType}" : $"{(char) transferMode}" }); if (typeResponse.FtpStatusCode != FtpStatusCode.CommandOK) { throw new FtpException(typeResponse.ResponseMessage); } }
/// <summary> /// Opens a data stream. /// </summary> /// <param name="session">The session handle.</param> /// <param name="transferMode">The mode.</param> /// <param name="streamMode">The stream mode.</param> /// <returns></returns> public static FtpStream OpenDataStream(this FtpSession session, FtpTransferMode transferMode, FtpStreamMode streamMode) { var client = session.Connection.Client; return(session.OpenDataStream(client.Passive, client.ConnectTimeout, client.ReadWriteTimeout, transferMode, streamMode)); }
/// <summary> /// Send STOR command. /// </summary> /// <param name="ftpClient">The FTP client.</param> /// <param name="path">The path.</param> /// <param name="mode">The mode.</param> /// <returns></returns> public static Stream Stor(this FtpClient ftpClient, FtpPath path, FtpTransferMode mode = FtpTransferMode.Binary) { return(ftpClient.Process(handle => ProcessStor(handle, path, mode))); }
public void SetTransferMode(FtpTransferMode mode) { CheckStateBeforeCommand(); FtpServerReply reply = SendCommand(FtpCommands.MODE, mode.ToCommand()); CheckReply(reply); TransferMode = mode; }
/// <summary> /// Opens the data stream. /// </summary> /// <param name="passive">if set to <c>true</c> [passive].</param> /// <param name="connectTimeout">The connect timeout.</param> /// <param name="readWriteTimeout">The read write timeout.</param> /// <param name="mode">The mode.</param> /// <returns></returns> public FtpStream OpenDataStream(bool passive, TimeSpan connectTimeout, TimeSpan readWriteTimeout, FtpTransferMode mode) { CheckProtection(FtpProtection.DataChannel); SetTransferMode(mode); FtpStream stream; if (passive) { stream = OpenPassiveDataStream(connectTimeout, readWriteTimeout); } else { stream = OpenActiveDataStream(connectTimeout, readWriteTimeout); } return(stream); }
/// <summary> /// Opens the data stream. /// </summary> /// <param name="passive">if set to <c>true</c> [passive].</param> /// <param name="connectTimeout">The connect timeout.</param> /// <param name="readWriteTimeout">The read write timeout.</param> /// <param name="transferMode">The mode.</param> /// <param name="streamMode">The stream mode.</param> /// <returns></returns> internal FtpStream OpenDataStream(bool passive, TimeSpan connectTimeout, TimeSpan readWriteTimeout, FtpTransferMode transferMode, FtpStreamMode?streamMode) { CheckProtection(FtpProtection.DataChannel, bufferSize: 0); SetTransferMode(transferMode); FtpStream stream; if (passive) { stream = OpenPassiveDataStream(connectTimeout, readWriteTimeout, streamMode); } else { stream = OpenActiveDataStream(connectTimeout, readWriteTimeout); } return(stream); }
/// <summary> /// Opens the data stream. /// </summary> /// <param name="passive">if set to <c>true</c> [passive].</param> /// <param name="connectTimeout">The connect timeout.</param> /// <param name="readWriteTimeout">The read write timeout.</param> /// <param name="transferMode">The transfer mode.</param> /// <param name="streamMode">The stream mode.</param> /// <returns></returns> public FtpStream OpenDataStream(bool passive, TimeSpan connectTimeout, TimeSpan readWriteTimeout, FtpTransferMode transferMode, FtpStreamMode streamMode) { return(OpenDataStream(passive, connectTimeout, readWriteTimeout, transferMode, (FtpStreamMode?)streamMode)); }
/// FTPサーバーへMODEコマンドを送信します。 /// <summary> /// Send mode command to ftp server. /// FTPサーバーへMODEコマンドを送信します。 /// <param name="mode">転送モード</param> /// <returns></returns> public Task <FtpCommandResult> ExecuteModeAsync(FtpTransferMode mode) { return(CreateNewTask <FtpCommandResult>(() => this.ExecuteMode(mode))); }