/// <summary> /// Populates the capabilities flags based on capabilities /// supported by this server. This method is overridable /// so that new features can be supported /// </summary> /// <param name="reply">The reply object from the FEAT command. The InfoMessages property will /// contain a list of the features the server supported delimited by a new line '\n' character.</param> internal void ParseFeatures(FtpResponse reply) { foreach (string feat in reply.InfoMessages.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries)) { if (feat.ToUpper().Trim().StartsWith("MLST") || feat.ToUpper().Trim().StartsWith("MLSD")) m_Caps |= FtpCapability.MLSD; else if (feat.ToUpper().Trim().StartsWith("MDTM")) m_Caps |= FtpCapability.MDTM; else if (feat.ToUpper().Trim().StartsWith("REST STREAM")) m_Caps |= FtpCapability.REST; else if (feat.ToUpper().Trim().StartsWith("SIZE")) m_Caps |= FtpCapability.SIZE; else if (feat.ToUpper().Trim().StartsWith("UTF8")) m_Caps |= FtpCapability.UTF8; else if (feat.ToUpper().Trim().StartsWith("PRET")) m_Caps |= FtpCapability.PRET; else if (feat.ToUpper().Trim().StartsWith("MFMT")) m_Caps |= FtpCapability.MFMT; else if (feat.ToUpper().Trim().StartsWith("MFCT")) m_Caps |= FtpCapability.MFCT; else if (feat.ToUpper().Trim().StartsWith("MFF")) m_Caps |= FtpCapability.MFF; } }
/// <summary> /// Initalizes a new instance of a FtpResponseException /// </summary> /// <param name="reply">The FtpReply to build the exception from</param> public FtpCommandException(FtpResponse reply) : this(reply.Code, reply.Message) { }
/// <summary> /// Retreives a reply from the server. Do not execute this method /// unless you are sure that a reply has been sent, i.e., you /// executed a command. Doing so will cause the code to hang /// indefinitely waiting for a server reply that is never comming. /// </summary> /// <returns>FtpReply representing the response from the server</returns> internal async Task<FtpResponse> GetReplyAsync() { var reply = new FtpResponse(); if (!IsConnected) throw new InvalidOperationException("No connection to the server has been established."); string buf; while ((buf = await m_Stream.ReadLineAsync(Encoding)) != null) { Match m; System.Diagnostics.Debug.WriteLine(buf); if ((m = Regex.Match(buf, "^(?<code>[0-9]{3}) (?<message>.*)$")).Success) { reply.Code = m.Groups["code"].Value; reply.Message = m.Groups["message"].Value; break; } reply.InfoMessages += string.Format("{0}\n", buf); } return reply; }