//public void DownloadFiles(string remoteFiles, string localDirectory, bool deleteRemoteFile = false) //{ // var directoryName = Path.GetDirectoryName(remoteFiles); // var remoteFileNames = GetDirectoryList(directoryName); // foreach (var remoteFileName in remoteFileNames) // { // var localFileName = Path.Combine(localDirectory, Path.GetFileName(remoteFileName)); // DownloadFile(remoteFileName, localFileName, deleteRemoteFile); // } //} public void UploadFile(string localFile, string remoteFile, bool deleteLocalFile = false) { var ftp = new FTPSClient(); try { ftp.Connect(this.host, new NetworkCredential(this.user, this.password), ESSLSupportMode.ClearText); ftp.SetTransferMode(this.UseBinary ? ETransferMode.Binary : ETransferMode.ASCII); //ftp.SetCurrentDirectory(remoteFolder); ftp.PutFile(localFile, remoteFile); if (deleteLocalFile == true) { ftp.DeleteFile(localFile); } } catch (Exception ex) { throw; } finally { if (ftp != null) { ftp.Close(); ftp.Dispose(); } } }
public void DeleteAllUpUntil(DateTime finalDate) { int deletedFiles = 0; _log.DebugFormat("Trying to delete all files created up until '{0}'", finalDate); using (FTPSClient client = new FTPSClient()) { // Connect to the server, with mandatory SSL/TLS // encryption during authentication and // optional encryption on the data channel // (directory lists, file transfers) client.Connect(_server.Authority, _credential, ESSLSupportMode.All, CertificateValidationCallback); var items = client.GetDirectoryList(); //adding root dir to guarantee old files deletion in it. items.Add(new DirectoryListItem() { IsDirectory = true, Name = "/" }); var dirs = items.Where <DirectoryListItem>(x => x.IsDirectory); foreach (var dir in dirs) { client.SetCurrentDirectory(dir.Name); var files = client.GetDirectoryList().Where <DirectoryListItem>(x => x.IsDirectory == false); foreach (var file in files) { try { if (!file.IsDirectory && file.CreationTime < finalDate) { client.DeleteFile(file.Name); deletedFiles++; } } catch (Exception e) { _log.ErrorFormat("'{0}' while deleting '{1}/{2}'", e.Message, dir.Name, file.Name); } } client.SetCurrentDirectory("/"); } } _log.DebugFormat("{0} files deleted", deletedFiles); }
public void Delete(Versandauftrag versandauftrag, Action onEndOfStream) { if (versandauftrag != null) { _ftp.DeleteFile(Build_filename(versandauftrag)); } else { onEndOfStream(); } }
public IEnumerable <string> DownloadFiles(string remoteFiles, string localDirectory, bool deleteRemoteFile = false) { var downloadedFiles = new List <string>(); var ftp = new FTPSClient(); try { ftp.Connect(this.host, new NetworkCredential(this.user, this.password), ESSLSupportMode.ClearText); ftp.SetTransferMode(this.UseBinary ? ETransferMode.Binary : ETransferMode.ASCII); //ftp.SetCurrentDirectory(remoteFolder); var directoryName = this.GetDirectoryName(remoteFiles); var remoteFileInfos = this.GetDirectoryList(directoryName); var remoteFilePattern = Path.GetFileName(remoteFiles); foreach (var remoteFileInfo in remoteFileInfos) { if (string.IsNullOrEmpty(remoteFilePattern) || FileUtil.MatchesWildcard(remoteFileInfo.Name, remoteFilePattern)) { var localFileName = Path.Combine(localDirectory, Path.GetFileName(remoteFileInfo.Name)); ftp.GetFile(remoteFileInfo.FullName, localFileName); downloadedFiles.Add(remoteFileInfo.FullName); if (deleteRemoteFile == true) { ftp.DeleteFile(remoteFileInfo.FullName); } } } } catch (Exception ex) { throw; } finally { if (ftp != null) { ftp.Close(); ftp.Dispose(); } } return(downloadedFiles); }
public static void DeleteFilesFromFTPServer(FTPSClient FTP, List <string> FilesToDelete, int WaitBetweenRecords, string RemoteDirectory, string Server) //, CancellationToken Token) { var errorRepository = ApplicationEventRepositoryFactory.Create(); foreach (var FTPFile in FilesToDelete) { try { FTP.DeleteFile(FTPFile); } catch (FTPException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " DeleteFilesFromFTPServer", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } catch (AggregateException) { Console.WriteLine("Connection Failure"); } catch (SocketException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " DeleteFilesFromFTPServer", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } catch (IOException ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " DeleteFilesFromFTPServer", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine(ex.Message); } catch (Exception ex) { errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", " DeleteFilesFromFTPServer", ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message); Console.WriteLine("Exception:" + ex.Message + " While Deleting file: " + FTPFile + " from " + RemoteDirectory + " on " + Server); } Thread.Sleep(WaitBetweenRecords); } }
public void DownloadFile(string remoteFile, string localFile, bool deleteRemoteFile = false) { var ftp = new FTPSClient(); var localDownloadFile = localFile; try { //ftp.Connect(hostname: host, // port: this.port, // credential: new NetworkCredential(this.user, this.password), // sslSupportMode: ESSLSupportMode.All, // userValidateServerCertificate: null, // x509ClientCert: null, // dataConnectionMode: EDataConnectionMode.Passive); ftp.Connect(this.host, new NetworkCredential(this.user, this.password), ESSLSupportMode.ClearText); ftp.SetTransferMode(this.UseBinary ? ETransferMode.Binary : ETransferMode.ASCII); //ftp.SetCurrentDirectory(remoteFolder); if (Directory.Exists(localFile) && !Path.HasExtension(localFile)) { localDownloadFile = Path.Combine(localFile, Path.GetFileName(remoteFile)); } ftp.GetFile(remoteFile, localDownloadFile); if (deleteRemoteFile == true) { ftp.DeleteFile(remoteFile); } } catch (Exception ex) { throw; } finally { if (ftp != null) { ftp.Close(); ftp.Dispose(); } } }
public override bool DeleteFile(File file) { _client.DeleteFile(file.Name); return(true); }
public void Delete(string remoteFileName) { Debug.WriteLine("Deleting from " + _host + ":" + _port + "/" + remoteFileName); client.DeleteFile(remoteFileName); Debug.WriteLine("Successfully deleted " + _host + ":" + _port + "/" + remoteFileName); }
private static void DoDeleteFile(FTPSClient client) { client.DeleteFile(NormalizeRemotePath(commandArguments[0])); }