/// <summary> /// Delete the specified remote file /// </summary> /// <param name="remoteFile"> name of remote file to /// delete /// /// </param> public void Delete(string remoteFile) { var reply = control.SendCommand("DELE " + remoteFile); lastValidReply = control.ValidateReply(reply, "250"); }
/// <summary> /// Change the remote working directory to /// that supplied /// </summary> /// <param name="dir"> name of remote directory to /// change to /// /// </param> public void Chdir(string directory) { var reply = control.SendCommand("CWD " + directory); lastValidReply = control.ValidateReply(reply, "250"); }
/// <summary> /// List a directory's contents as an array of strings. A detailed /// listing is available, otherwise just filenames are provided. /// The detailed listing varies in details depending on OS and /// FTP server. Note that a full listing can be used on a file /// name to obtain information about a file /// </summary> /// <param name="dirname"> /// name of directory ( <b>not</b> a file mask ) /// </param> /// <param name="full"> /// true if detailed listing required false otherwise /// </param> /// <returns> /// an array of directory listing strings /// </returns> public string[] Dir(string directoryName, bool full) { // set up data channel data = control.CreateDataSocket(connectMode); // send the retrieve command var command = full ? "LIST " : "NLST "; if (directoryName != null) { command += directoryName; } // some FTP servers bomb out if NLST has whitespace appended command = command.Trim(); var reply = control.SendCommand(command); // check the control response. wu-ftp returns 550 if the // directory is empty, so we handle 550 appropriately var validCodes1 = new string[] { "125", "150", "550" }; lastValidReply = control.ValidateReply(reply, validCodes1); // an empty array of files for 550 var result = new string[0]; // a normal reply ... extract the file list if (!lastValidReply.Code.Equals("550")) { // get an character input stream to read data from . var reader = new StreamReader(GetDataStream()); // read a line at a time var lines = new ArrayList(); string line = null; while ((line = reader.ReadLine()) != null) { lines.Add(line); } try { reader.Close(); } catch (IOException exception) { Console.WriteLine(exception.Message); } // check the control response var validCodes2 = new string[] { "226", "250" }; reply = control.ReadReply(); lastValidReply = control.ValidateReply(reply, validCodes2); // empty array is default if (lines.Count > 0) { result = (string[])lines.ToArray(typeof(string)); } } return(result); }