/// <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); }
/// <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); }