/// <summary> /// Processes the list. /// </summary> /// <param name="session">The handle.</param> /// <param name="path">The path.</param> /// <returns></returns> private static IList <string> ProcessList(FtpSession session, FtpPath path) { // Open data channel using (var dataStream = OpenDataStream(session, FtpTransferMode.Binary, FtpStreamMode.Read)) { // then command is sent var reply = session.Expect(session.SendCommand("LIST", session.Connection.Client.GetPlatform(session).EscapePath(path.ToString())), 125, 150, 425); if (!reply.Code.IsSuccess) { dataStream.Abort(); session.ThrowException(reply); } using (var streamReader = new StreamReader(dataStream.Validated(), session.Connection.Encoding)) { var list = new List <string>(); for (;;) { var line = streamReader.ReadLine(); if (line == null) { break; } list.Add(line); } return(list); } } }
/// <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()); }
/// <summary> /// Loads the features. /// </summary> /// <param name="session">The session.</param> /// <returns></returns> private static FtpServerFeatures LoadServerFeatures(FtpSession session) { var featuresReply = session.SendCommand("FEAT"); if (featuresReply.Code == 211) { var featuresQuery = from line in featuresReply.Lines.Skip(1).Take(featuresReply.Lines.Length - 2) select line.Trim(); return(new FtpServerFeatures(featuresQuery)); } return(new FtpServerFeatures(new string[0])); }
private static FtpEntry ProcessGetEntry(FtpSession session, FtpPath path) { session.CheckProtection(FtpProtection.ControlChannel); var reply = session.SendCommand("STAT", session.Connection.Client.GetPlatform(session).EscapePath(path.ToString())); if ((reply.Code != 213 && reply.Code != 211) || reply.Lines.Length <= 2) { return(null); } // now get the type: the first entry is "." for folders or file itself for files/links var entry = EnumerateEntries(session.Connection.Client, path, reply.Lines.Skip(1), ignoreSpecialEntries: false).First(); // actually, it's always good here return(new FtpEntry(path, entry.Size, entry.Type, entry.Date, entry.Target)); }