public bool DownloadToLocal(string localPath, string Path, string Filename) { try { if (_ftpClient.DirectoryExists(Path)) { _ftpClient.RetryAttempts = 10; string fullpath = Path + Filename; using (MemoryStream ms = new MemoryStream()) { _log.Info($"{FtpTemplateMessage("DownloadLocal", Filename, "Downloading")}", fullpath); return(_ftpClient.DownloadFile(localPath, fullpath, FtpLocalExists.Overwrite)); } } else { _log.Info($"{FtpTemplateMessage("DownloadLocal", Filename, "Not Exist")}", Path + Filename); throw new Exception("File Not Exist"); } } catch (Exception ex) { _log.Error($"{FtpTemplateMessage("DownloadLocal", Filename, "throw exception")}", ex); throw ex; } }
/// <summary> /// Загрузка файла /// </summary> public void GetFile(string sourceFileName, string destFileName) { if (ftpClient.IsConnected) { ftpClient.DownloadFile(destFileName, sourceFileName); } }
private void BackupDirectory(IFtpClient client, string remotePath, string localPath, bool isDel) { var items = client.GetListing(remotePath); foreach (var item in items) { if (!client.IsConnected) { client.Connect(); } if (item.Type == FtpFileSystemObjectType.File) { var size = client.GetFileSize(item.FullName); var localFile = Path.Combine(localPath, item.Name); if (!File.Exists(localFile) || new FileInfo(localFile).Length != size) { client.DownloadFile(localFile, item.FullName); Logger.Info($"Downloaded==>{item.FullName}"); } } else if (item.Type == FtpFileSystemObjectType.Directory) { if (!Directory.Exists(item.FullName)) { Directory.CreateDirectory(item.FullName); Logger.Info($"CreateDirectory==>{item.FullName}"); } BackupDirectory(client, item.FullName, Path.Combine(localPath, item.Name), isDel); } } if (isDel) { var localFolder = new DirectoryInfo(localPath); var infos = localFolder.GetFileSystemInfos(); foreach (var info in infos) { if (items.All(item => item.Name != info.Name)) { if (info is DirectoryInfo) { (info as DirectoryInfo).Delete(true); } else { info.Delete(); } Logger.Info($"Deleted==>{info.FullName}"); } } } }
public Stream Download(string fileName) { try { return(ftpClient.DownloadFile(fileName)); } catch (Exception e) { TraceSource.TraceWarning("File cannot be found on ftp server, the transfer will be skipped. local name {0}. Error: {1}", fileName, e.Message); return(null); } }
/// <summary> /// Get all the listed traded symbols for for all major stock exchanges from nasdaq ftp /// </summary> /// <param name="syncSettings">The <see cref="ExchangeSyncSetting"/> containing sync settings.</ExchangeSyncSetting> </param> /// <returns>IReadOnlyDictionary with <see cref="SymbolKey"/> as key and <see cref="DownloadedSymbol"/> for the value.</returns> public async Task <IReadOnlyDictionary <SymbolKey, DownloadedSymbol> > GetTradedSymbols(ExchangeSyncSetting syncSettings) { _logger.LogTrace("Executing query http request url: {url}", syncSettings.Url); // no login necessary using var stream = _ftpClient.DownloadFile(syncSettings.Url, string.Empty, string.Empty); using StreamReader reader = new StreamReader(stream); var tickerToSymbols = await _parser.GetSymbolMap(reader, syncSettings.Delimiter, syncSettings.SuffixBlackList); return(new ReadOnlyDictionary <SymbolKey, DownloadedSymbol>(tickerToSymbols)); }
private void ProcessPricatFiles(IFtpClient client, ISimpleArchiveService archiver) { var successArchive = Path.Combine(PricatSettings.VendorArchive, SuccessDirectoryName); var errorArchive = Path.Combine(PricatSettings.VendorArchive, ErrorDirectoryName); var sessionStart = DateTime.Now; foreach (var remoteFile in client.Files.Where(file => file.FileName.EndsWith(".csv", StringComparison.CurrentCultureIgnoreCase))) { var remoteFileName = remoteFile.FileName; using (var fileStream = client.DownloadFile(remoteFileName)) { TraceVerbose("Processing file '{0}'...", remoteFileName); var lines = ReadRawPricatLines(fileStream); _currentRemoteFileName = remoteFileName; var importSuccess = ProcessPricatFile(lines); var intendedArchive = importSuccess ? successArchive : errorArchive; if (archiver.ArchiveLines(lines, intendedArchive, sessionStart, remoteFileName)) { if (intendedArchive == successArchive) { TraceInformation("The PRICAT-file '{0}' has been archived to the '{1}'-folder.", remoteFileName, intendedArchive); } else { TraceWarning("The PRICAT-file '{0}' has been archived to the '{1}'-folder.", remoteFileName, intendedArchive); } } else { TraceError("Failed to archive the PRICAT-file '{0}' into the '{1}'-folder.", remoteFileName, intendedArchive); } //Move file on the FTP if (!client.TryMoveFile(remoteFileName, importSuccess ? SuccessDirectoryName : ErrorDirectoryName)) { TraceError("Moving file '{0}' to the folder '{1}' on the FTP failed.", remoteFileName, importSuccess ? SuccessDirectoryName : ErrorDirectoryName); } } } //TraceVerbose("Generating product attribute configuration..."); // DS: Inactive as for 2014-07-15 //Database.Execute("EXEC [GenerateProductAttributeConfiguration] @0", "Color, Size, Subsize"); //TODO: SP missing in database }
public virtual void DownloadFile(string SavePath) { IFtpClient pFtpClient = SysDBConfig.GetInstance().GetFtpClient("CHXQ"); pFtpClient.Connect(); try { pFtpClient.DownloadFile(SavePath, this.Path); } catch (Exception ex) { throw ex; } finally { pFtpClient.Close(); } }
// 下载文件到本地 public void DownloadFile(string fileName) { // 选择路径 string name = Path.GetFileName(fileName); string saveFileName = FileUtils.SaveFilePathName(name, null, null); if (saveFileName != null) { try { ftpClient.DownloadFile(fileName, saveFileName); } catch (Exception e) { MessageBox.Show("FTP连接异常:" + e.Message); return; } } }
public virtual void DownloadFile(string remotePathAndFile, string localPathAndFile) { _ftpClient.Host = _configuration.FtpHost; _ftpClient.Credentials = new NetworkCredential(_configuration.FtpUsername, _configuration.FtpPassword); try { // begin connecting to the server _ftpClient.Connect(); _ftpClient.DownloadFile(localPathAndFile, remotePathAndFile); } catch (Exception ex) { throw new FtpException(ex.Message); } finally { _ftpClient.Disconnect(); } }
public void DownloadAD(string SavePath) { if (string.IsNullOrEmpty(m_CADPath)) { throw new Exception("图纸未上传"); } IFtpClient pFtpClient = HR.Utility.SysDBConfig.GetInstance().GetFtpClient("CHXQ"); pFtpClient.Connect(); try { pFtpClient.DownloadFile(SavePath, this.m_CADPath); } catch (Exception ex) { throw ex; } finally { pFtpClient.Close(); } }