Exemplo n.º 1
0
 public FtpProtocolException(FtpReply reply)
     : base("Invalid FTP protocol reply: " + reply)
 {
     _reply = reply;
 }
Exemplo n.º 2
0
 public FtpCommandException(FtpReply reply)
     : base(reply.Message)
 {
     _errorCode = reply.Code;
 }
Exemplo n.º 3
0
 public FtpProtocolException(FtpReply reply)
     : base("Invalid FTP protocol reply: " + reply)
 {
     _reply = reply;
 }
Exemplo n.º 4
0
 public LogServerReplyEventArgs(FtpReply serverReply)
 {
     ServerReply = serverReply;
 }
Exemplo n.º 5
0
        private IPEndPoint ParseEpsvReply(FtpReply reply)
        {
            string[] parts = reply.Message.Split('|');
            if (parts.Length != 5)
                throw new FtpProtocolException(reply);

            int port = int.Parse(parts[3]);
            return new IPEndPoint(((IPEndPoint)_ctrlClient.Client.LocalEndPoint).Address, port);
        }
Exemplo n.º 6
0
 public FtpCommandException(FtpReply reply)
     : base(reply.Message)
 {
     _errorCode = reply.Code;
 }
Exemplo n.º 7
0
        private FtpReply GetReply()
        {
            try {
                FtpReply reply = new FtpReply();
                bool replyDone = false;

                do {
                    string replyLine = _ctrlSr.ReadLine();

                    Match m = Regex.Match(replyLine, @"^([0-9]{3})([\s\-])(.*)$");

                    if (m.Success) {
                        int code = int.Parse(m.Groups[1].Value);
                        string messageLine = m.Groups[3].Value;
                        replyDone = (m.Groups[2].Value == " ");

                        if (reply.Code == 0) {
                            reply.Code = code;
                            reply.Message = messageLine;
                        } else // Multiline message
                        {
                            if (reply.Code != code)
                                throw new FtpReplyParseException(replyLine);

                            reply.Message += "\r\n" + messageLine;
                        }
                    } else // Multiline message
                    {
                        if (reply.Code == 0)
                            throw new FtpReplyParseException(replyLine);

                        reply.Message += "\r\n" + replyLine.TrimStart();
                    }
                }
                while (!replyDone);

                _waitingCompletionReply = (reply.Code < 200);

                if (LogServerReply != null)
                    LogServerReply(this, new LogServerReplyEventArgs(reply));

                if (reply.Code >= 400)
                    throw new FtpCommandException(reply);

                return reply;
            } catch (Exception) {
                _waitingCompletionReply = false;
                throw;
            }
        }
Exemplo n.º 8
0
 private static string ParseStouReply(FtpReply reply)
 {
     string fileName;
     int i = reply.Message.LastIndexOf(' ');
     if (i < 0)
         throw new FtpProtocolException(reply);
     fileName = reply.Message.Substring(i + 1, reply.Message.Length - i - 2);
     return fileName;
 }
Exemplo n.º 9
0
        private static string ParsePwdReply(FtpReply reply)
        {
            int i = reply.Message.IndexOf('\"');
            if (i < 0)
                throw new FtpProtocolException(reply);

            int j = reply.Message.IndexOf('\"', i + 1);
            if (j < 0)
                throw new FtpProtocolException(reply);

            string dirName = reply.Message.Substring(i + 1, j - i - 1);
            return dirName;
        }
Exemplo n.º 10
0
        private static IPEndPoint ParsePasvReply(FtpReply reply)
        {
            IPEndPoint dataEndPoint;
            int i = reply.Message.IndexOf('(');
            if (i < 0)
                throw new FtpProtocolException(reply);

            int j = reply.Message.IndexOf(')', i + 1);
            if (j < 0)
                throw new FtpProtocolException(reply);

            string[] parts = reply.Message.Substring(i + 1, j - i - 1).Split(',');
            if (parts.Length != 6)
                throw new FtpProtocolException(reply);

            byte[] addr = new byte[4];
            for (i = 0; i < addr.Length; i++)
                addr[i] = byte.Parse(parts[i]);

            int port = byte.Parse(parts[4]) * 256 + byte.Parse(parts[5]);

            dataEndPoint = new IPEndPoint(new IPAddress(addr), port);
            return dataEndPoint;
        }
Exemplo n.º 11
0
 public LogServerReplyEventArgs(FtpReply serverReply)
 {
     ServerReply = serverReply;
 }