private string SetupDirDetails(string dirname) { // create the factory if (fileFactory == null) fileFactory = new FTPFileFactory(); // initialize if not yet done if (!fileFactory.ParserSetExplicitly && fileFactory.System == null) { try { fileFactory.System = GetSystem(); } catch (FTPException ex) { log.Warn("SYST command failed - setting Unix as default parser", ex); fileFactory.System = FTPFileFactory.UNIX_STR; } } if (parserCulture != null) fileFactory.ParsingCulture = parserCulture; string path = ""; try { path = Pwd(); } catch (FTPException ex) { log.Warn("Failed to find current directory: " + ex.Message); } // get the path from the supplied dirname string dirPath = dirname != null ? PathUtil.GetFolderPath(dirname) : ""; // combine it with the current directory if (dirPath.Length > 0 && dirPath.Length < dirname.Length) { if (dirPath.StartsWith("/")) path = dirPath; else path = PathUtil.Combine(path, dirPath); } return path; }
/// <summary> /// Quit the FTP session immediately by closing the control socket /// without sending the QUIT command /// </summary> public virtual void QuitImmediately() { CheckConnection(true); fileFactory = null; control.Logout(); control = null; }
/// <summary> /// List a directory's contents as an array of FTPFile objects. /// Should work for Windows and most Unix FTP servers - let us know /// about unusual formats ([email protected]) /// </summary> /// <param name="dirname"> name of directory OR filemask /// </param> /// <returns> an array of FTPFile objects /// </returns> public virtual FTPFile[] DirDetails(string dirname) { // create the factory if (fileFactory == null) fileFactory = new FTPFileFactory(GetSystem()); // get the details and parse return fileFactory.Parse(Dir(dirname, true)); }
/// <summary> /// Quit the FTP session /// </summary> public virtual void Quit() { CheckConnection(true); fileFactory = null; try { FTPReply reply = control.SendCommand("QUIT"); string[] validCodes = new string[]{"221", "226"}; lastValidReply = control.ValidateReply(reply, validCodes); } finally { // ensure we clean up the connection control.Logout(); control = null; } }