/// <summary> /// Initializes a new instance of the <see cref="ProtocolMessageEventArgs"/> class. /// </summary> /// <param name="sessionID">The session ID.</param> /// <param name="requestCommand">The request command.</param> /// <param name="requestParameters">The request parameters.</param> /// <param name="reply">The reply.</param> public ProtocolMessageEventArgs(int sessionID, string requestCommand = null, string[] requestParameters = null, FtpReply reply = null) { SessionID = sessionID; RequestCommand = requestCommand; RequestParameters = requestParameters; Reply = reply; }
/// <summary> /// Throws the exception given a reply. /// </summary> /// <param name="reply">The reply.</param> /// <exception cref="FtpFileException"></exception> /// <exception cref="FtpProtocolException"></exception> /// <exception cref="FtpTransportException"></exception> internal void ThrowException(FtpReply reply) { if (reply.Code.Class == FtpReplyCodeClass.Filesystem) { throw new FtpFileException(string.Format("File error. Code={0} ('{1}')", reply.Code.Code, reply.Lines[0]), reply.Code); } if (reply.Code.Class == FtpReplyCodeClass.Connections) { throw new FtpTransportException(string.Format("Connection error. Code={0} ('{1}')", reply.Code.Code, reply.Lines[0])); } throw new FtpProtocolException(string.Format("Expected other reply than {0} ('{1}')", reply.Code.Code, reply.Lines[0]), reply.Code); }
/// <summary> /// Expects the specified reply. /// </summary> /// <param name="reply">The reply.</param> /// <param name="codes">The codes.</param> /// <returns></returns> public FtpReply Expect(FtpReply reply, params int[] codes) { if (!codes.Any(code => code == reply.Code)) { // When 214 is unexpected, it may create a command/reply inconsistency (a 1-reply shift) // so the best option here is to disconnect, it will reset the command/reply pairs if (reply.Code == 214) { Connection.Disconnect(); } ThrowException(reply); } return(reply); }
/// <summary> /// Processes the read reply. /// </summary> /// <param name="stream">The stream.</param> /// <returns></returns> private FtpReply ProcessReadReply(Stream stream) { var reply = new FtpReply(); { for (;;) { var line = ReadLine(() => ReadByte(stream)); if (line == null) { Connection.Disconnect(); throw new FtpTransportException(string.Format("Error while reading reply ({0})", reply.Lines != null ? String.Join("//", reply.Lines) : "null")); } if (!reply.ParseLine(line)) { break; } } } Connection.Client.OnReply(new ProtocolMessageEventArgs(Connection.ID, null, null, reply)); return(reply); }