Exemplo n.º 1
0
 /// <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);
         }
     }
 }
Exemplo n.º 2
0
        /// <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());
        }