示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="command"></param>
        private void sendCommand(String command)
        {
            if (this.verboseDebugging)
            {
                Debug.WriteLine(command, "FtpClient");
            }

            Byte[] cmdBytes = FtpEncoding.GetBytes((command + "\r\n").ToCharArray());
            clientSocket.Send(cmdBytes, cmdBytes.Length, 0);
            this.readResponse();
        }
示例#2
0
        /// <summary>
        /// Return a string array containing the remote directory's file list.
        /// </summary>
        /// <param name="mask"></param>
        /// <returns></returns>
        public string[] GetFileList(string mask)
        {
            if (!this.loggedin)
            {
                this.Login();
            }

            Socket cSocket = createDataSocket();

            this.sendCommand("NLST " + mask);

            if (!(this.resultCode == 150 || this.resultCode == 125))
            {
                throw new FtpException(this.result.Substring(4));
            }

            this.message = "";

            DateTime timeout = DateTime.Now.AddSeconds(this.timeoutSeconds);

            while (timeout > DateTime.Now)
            {
                int bytes = cSocket.Receive(buffer, buffer.Length, 0);
                this.message += FtpEncoding.GetString(buffer, 0, bytes);

                if (bytes < this.buffer.Length)
                {
                    break;
                }
            }

            string[] msg = this.message.Replace("\r", "").Split('\n');

            cSocket.Close();

            if (this.message.IndexOf("No such file or directory") != -1)
            {
                msg = new string[] {}
            }
            ;

            this.readResponse();

            if (this.resultCode != 226)
            {
                msg = new string[] {}
            }
            ;
            //	throw new FtpException(result.Substring(4));

            return(msg);
        }
        public static String valueOf(FtpEncoding ftpEncoding, Error error)
        {
            switch (ftpEncoding)
            {
            case FtpEncoding.BINARY:
                return("BINARY");

            case FtpEncoding.ASCII:
                return("ASCII");

            default:
                error.setError("FE002", "Unknown encoding");
                return("");
            }
        }
 public FtpsOptions() : base()
 {
     this._host               = "";
     this._port               = 21;
     this._user               = "";
     this._password           = "";
     this._forceEncryption    = true;
     this._connectionMode     = FtpConnectionMode.PASSIVE;
     this._encoding           = FtpEncoding.BINARY;
     this._encryptionMode     = FtpEncryptionMode.EXPLICIT;
     this._trustStorePath     = "";
     this._trustStorePassword = "";
     this._protocol           = FtpsProtocol.TLS1_2;
     this._whiteList          = null;
 }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private string readLine()
        {
            while (true)
            {
                this.bytes    = clientSocket.Receive(this.buffer, this.buffer.Length, 0);
                this.message += FtpEncoding.GetString(this.buffer, 0, this.bytes);

                if (this.bytes < this.buffer.Length)
                {
                    break;
                }
            }

            string[] msg = this.message.Split('\n');

            if (this.message.Length > 2)
            {
                this.message = msg[msg.Length - 2];
            }

            else
            {
                this.message = msg[0];
            }


            if (this.message.Length > 4 && !this.message.Substring(3, 1).Equals(" "))
            {
                return(this.readLine());
            }

            if (this.verboseDebugging)
            {
                for (int i = 0; i < msg.Length - 1; i++)
                {
                    Debug.Write(msg[i], "FtpClient");
                }
            }

            return(message);
        }