public override int Run(string[] paths) { //this.path = paths[0]; this.path = paths[0].Replace(@"\", "/"); Console.WriteLine(path); // create a new FtpClient object with the host and port number to use // (optionally create a secure SSL connection) ftp = new Starksoft.Net.Ftp.FtpClient(host, 21); // specify a binary, passive connection with no zlib file compression ftp.FileTransferType = TransferType.Binary; ftp.DataTransferMode = TransferMode.Passive; // open a connection to the ftp server ftp.Open(username, password); // change to the directory on the ftp server specified in cmd line option //ftp.ChangeDirectory(path); // retrieve a listing of the files in the directory as a collection of FtpItem objects FtpItemCollection col = new FtpItemCollection(); if (string.IsNullOrEmpty(recurse)) { col = ftp.GetDirList(path); } else { col = ftp.GetDirListDeep(path); } foreach (FtpItem item in col) { Console.WriteLine("{0}\t{1}\t{2}", item.Modified.ToString(), item.ItemType.ToString(), item.FullPath); } // close connection to the ftp server ftp.Close(); return 0; }
public void RecursiveDeleteFTP(string path, bool RemFromLog, ref FtpClient ftpclient) { foreach (FtpItem fi in ftpclient.GetDirList(path)) { if (fi.ItemType == FtpItemType.File) { string fpath = string.Format("{0}/{1}", path, fi.Name); Log.Write(l.Info, "Gon'delete: {0}", fpath); ftpclient.DeleteFile(fpath); if (RemFromLog) RemoveFromLog(fpath); } else if (fi.ItemType == FtpItemType.Directory) { if (fi.Name != "." && fi.Name != "..") { string fpath = string.Format("{0}/{1}", noSlashes(path), fi.Name); RecursiveDeleteFTP(fpath, RemFromLog, ref ftpclient); } } } ftpclient.DeleteDirectory(path); if (RemFromLog) RemoveFromLog(path); }