示例#1
0
        /// <summary>
        /// 
        /// </summary>
        protected void CreatePassiveFtpSocketInformation()
        {
            // Most answers are in a pattern like
            // 227 blah blah blah (ip0,ip1,ip2,ip3,prt0,prt1)
            // So first find ( and than ) and in between you find the
            // IP addres and the port which has to be calculated.
            // prt0 must be multiplied by 256 and prt1 must be added to the calculation to get the 'listeners port'

            /*
             Official documentation:
                Tells the server to enter "passive mode".
                In passive mode, the server will wait for the client to establish a connection with it
                rather than attempting to connect to a client-specified port.

                The server will respond with the address of the port it is listening on, with a message like:
                227 Entering Passive Mode (a1,a2,a3,a4,p1,p2)
                where a1.a2.a3.a4 is the IP address and p1*256+p2 is the port number.
             */
            var startPart = ftpProg.FtpResponse.LastIndexOf("(") + 1;
            var endPart = ftpProg.FtpResponse.LastIndexOf(")");
            var passsiveResult = ftpProg.FtpResponse.Substring(startPart, endPart - startPart);
            var results = passsiveResult.Split(',');
            storSendTo = new FtpPassiveConnection();
            storSendTo.PassiveIP = IPAddress.Parse(String.Format("{0}.{1}.{2}.{3}", results[0], results[1], results[2], results[3]));
            storSendTo.PasssivePortNr = (Convert.ToInt32(results[4]) * 256) + Convert.ToInt32(results[5]);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        protected void CreatePassiveFtpSocketInformation()
        {
            // Most answers are in a pattern like
            // 227 blah blah blah (ip0,ip1,ip2,ip3,prt0,prt1)
            // So first find ( and than ) and in between you find the
            // IP addres and the port which has to be calculated.
            // prt0 must be multiplied by 256 and prt1 must be added to the calculation to get the 'listeners port'

            /*
             * Official documentation:
             *  Tells the server to enter "passive mode".
             *  In passive mode, the server will wait for the client to establish a connection with it
             *  rather than attempting to connect to a client-specified port.
             *
             *  The server will respond with the address of the port it is listening on, with a message like:
             *  227 Entering Passive Mode (a1,a2,a3,a4,p1,p2)
             *  where a1.a2.a3.a4 is the IP address and p1*256+p2 is the port number.
             */
            var startPart      = ftpProg.FtpResponse.LastIndexOf("(") + 1;
            var endPart        = ftpProg.FtpResponse.LastIndexOf(")");
            var passsiveResult = ftpProg.FtpResponse.Substring(startPart, endPart - startPart);
            var results        = passsiveResult.Split(',');

            storSendTo                = new FtpPassiveConnection();
            storSendTo.PassiveIP      = IPAddress.Parse(String.Format("{0}.{1}.{2}.{3}", results[0], results[1], results[2], results[3]));
            storSendTo.PasssivePortNr = (Convert.ToInt32(results[4]) * 256) + Convert.ToInt32(results[5]);
        }