public void TestMethod1() { FtpDownloader ftp = new FtpDownloader(@"ftp://jacobgudbjerg.dk", "", ""); //Assert.IsTrue(ftp.TryPutFile("TestFile2.txt", "Dette er en test\n")); }
private IDownloader ConstructDownloader(Host host, IDestination destination) { if (!trackingInformation.TryGetValue(host.Address, out var downloader)) { var tracking = new HostTracking(config.YiFtp, host); downloader = new FtpDownloader(tracking, destination, filePredicate); trackingInformation[host.Address] = downloader; } return(downloader); }
public new void Load(ServersTreeNodes.RemoteFileNode node, Tabs tabs) { ftp = true; Data = node.data; ftpFile = node.GetFile(); FtpDownloader downloader = new FtpDownloader(); string ftpIp = node.data.adress.Replace("/", "").Split(':')[1]; string ftpLocalFileName = Main.TempRemoteDirectory + ftpIp + Path.DirectorySeparatorChar + Path.GetFileName(node.GetFile()); downloader.Download(node.data, ftpLocalFileName, node.GetFile()); Load(new FileInfo(ftpLocalFileName), tabs); }
public new void Load(Data.RemoteServer _data, string file, Tabs tabs) { ftp = true; Data = _data; ftpFile = file; FtpDownloader downloader = new FtpDownloader(); string ftpIp = this.Data.adress.Replace("/", "").Split(':')[1]; string ftpLocalFileName = Main.TempRemoteDirectory + ftpIp + Path.DirectorySeparatorChar + Path.GetFileName(file); downloader.Download(Data, ftpLocalFileName, file); Load(new FileInfo(ftpLocalFileName), tabs); }
public void DownloadTest() { string uri = @"ftp://www.pilotvision.co.jp/googlehostedservice.html"; string userName = "******"; string password = "******"; FtpDownloader target = new FtpDownloader(userName, password); MemoryStream actual = null; actual = target.Download(uri); Assert.IsNotNull(actual); Assert.IsTrue(actual.Length > 0); }
public void ExistsFileTest() { string uri = @"ftp://www.pilotvision.co.jp/googlehostedservice.html"; string userName = "******"; string password = "******"; FtpDownloader target = new FtpDownloader(userName, password); var actual = target.ExistsFile(uri); Assert.AreEqual(true, actual); uri = @"ftp://www.pilotvision.co.jp/foo.bar"; actual = target.ExistsFile(uri); Assert.AreEqual(false, actual); }
public MainWindow() { InitializeComponent(); _viewModel = new MainViewModel(); DataContext = _viewModel; var settings = new Settings { NormalRecheckTime = Properties.Settings.Default.NormalRecheckTime, ExpeditedRecheckTime = Properties.Settings.Default.ExpeditedRecheckTime, FtpRootCheckDir = Properties.Settings.Default.FTPRootCheckDir, TempDownloadPath = Properties.Settings.Default.TempDownloadPath, RemapFile = Properties.Settings.Default.RemapFile, MaxRetryCount = Properties.Settings.Default.MaxRetryCount, ProgressBarSize = Properties.Settings.Default.ProgressBarSize, VideoRootPath = Properties.Settings.Default.VideoRootPath, BatchDownloads = Properties.Settings.Default.BatchDownloads, FtpUserName = Properties.Settings.Default.FTPUserName, FtpPassword = Properties.Settings.Default.FTPPassword, FtpUrl = Properties.Settings.Default.FTPUrl, BatchDownloadSize = Properties.Settings.Default.BatchDownloadSize, EnableProcessing = Properties.Settings.Default.EnableProcessing }; _downloader = new FtpDownloader(settings, new FtpEvents { UpdatedProgressHandler = updateProgressBar, DownloadStartedHandler = downloadStarted, DownloadErrorHandler = downloadError, DownloadCompletedHandler = downloadCompleted, CleanupCompletedHandler = cleanupCompleted, CleanupStartedHandler = cleanupStarted }); FtpWrapper.DownloadList.OnAdd += downloadListOnOnAdd; _downloader.BeginProcess(); }
public virtual CertificateCatalogFile GetCatalogFile(CertificateSource source, FileCleaner cleaner) { var downloader = new FtpDownloader(); var uri = new Uri(source.DecodeTableUrl); if (uri.Scheme.Match("ftp")) { var downloadFiles = downloader.DownloadedFiles(uri, source.LastDecodeTableDownload.HasValue ? source.LastDecodeTableDownload.Value : DateTime.MinValue, DownHandlerPath); if (downloadFiles.Count > 0) { return(new CertificateCatalogFile(source, downloadFiles[0].FileDate, downloadFiles[0].FileName)); } else { _logger.DebugFormat("Файл {0} не найден", uri); } } else if (uri.Scheme.Match("file")) { var src = new FileInfo(uri.LocalPath); if (!src.Exists) { return(null); } //в базе даты хранятся с точнотью до секунды сравнивать их нужно так же if (Math.Abs((DateTime.Now - src.LastWriteTime).TotalMilliseconds) > Settings.Default.FileDownloadInterval && Math.Abs((source.LastDecodeTableDownload.GetValueOrDefault() - src.LastWriteTime).TotalSeconds) > 1) { var dst = src.CopyTo(cleaner.TmpFile(), true); return(new CertificateCatalogFile(source, src.LastWriteTime, dst.FullName)); } } return(null); }
private void VerifyButton_Click(object sender, EventArgs e) { if (liveriesFolder == null || ModFolder == null) { return; } if (verifyTask != null && !verifyTask.IsCompleted) { return; } if (downloadTask != null && !downloadTask.IsCompleted) { return; } verifyTask = Task.Factory.StartNew((Action)(() => { filesThatRequireUpdate.Clear(); //Create Mods if it doesn't exist if (!Directory.Exists(ModFolder)) { Directory.CreateDirectory(ModFolder); } string LivFolder = Path.Combine(ModFolder, "Liveries"); if (!Directory.Exists(LivFolder)) { Directory.CreateDirectory(LivFolder); } //Create Liveries folder if it doesn't exist if (!Directory.Exists(liveriesFolder)) { Directory.CreateDirectory(liveriesFolder); } //Reset the progress bar Invoke(new MethodInvoker(() => { progressBar1.Visible = false; progressBar1.Value = 0; progressBar1.Maximum = 1; })); //Reset the Update Status Light filesAreInSync = false; updateStatus.BackgroundImage = Properties.Resources.red_light; string dcsModsURL = "ftp://dcs.btac.pro/"; SetCurrentAction("Getting current list of files from the server..."); Invoke(new MethodInvoker(() => { progressBar1.Show(); progressBar1.Style = ProgressBarStyle.Marquee; progressBar1.MarqueeAnimationSpeed = 50; })); var FtpDownloader = new FtpDownloader(); List <WebFileInfo> allFilesOnWebserver; try { allFilesOnWebserver = FtpDownloader.GetFilesFromDirectoryListing(dcsModsURL); } catch (Exception ex) { Invoke(new MethodInvoker(() => { progressBar1.Style = ProgressBarStyle.Continuous; progressBar1.Hide(); })); SetCurrentAction("Could not get a file list from the server. Please try again later." + Environment.NewLine + "Cause: " + ex.Message); return; } Invoke(new MethodInvoker(() => { progressBar1.Style = ProgressBarStyle.Continuous; progressBar1.Hide(); })); List <FilePair> pairs = new List <FilePair>(); //Add the files from the web server pairs.AddRange(allFilesOnWebserver.Select(webFileInfo => { //remove the working directory from the front string redactedURL = webFileInfo.URL.Replace("/" + FtpDownloader.FTP_WORKING_DIRECTORY, ""); string localFilename = Path.GetFullPath(ModFolder + redactedURL); var pair = new FilePair(webFileInfo, localFilename); return(pair); })); //Add the local files (which don't have an web counterpart) var localFiles = Directory.GetFiles(ModFolder, "*.*", SearchOption.AllDirectories); var localFilesNotOnWebServer = localFiles .Where(f => !pairs.Exists(p => p.LocalFilename.Equals(f))) .Select(f => new FilePair(null, f)) .ToList(); pairs.AddRange(localFilesNotOnWebServer); pairs.ForEach(pair => { if (pair.RequiresUpdate()) { filesThatRequireUpdate.Add(pair); } }); if (filesThatRequireUpdate.Count == 0) { SetCurrentAction("All files are up to date. No downloads are required."); filesAreInSync = true; updateStatus.BackgroundImage = Properties.Resources.green_light; } else { var filesToDownload = filesThatRequireUpdate.Where(f => f.RemoteFileInfo != null); var totalFilesToDownload = filesToDownload.Count(); var totalBytesToDownload = filesToDownload.Sum(f => f.RemoteFileInfo.Length); var totalBytesToDownloadAsString = BytesToString(totalBytesToDownload); var filesToDelete = filesThatRequireUpdate.Where(f => f.RemoteFileInfo == null); var totalFilesToDelete = filesToDelete.Count(); string sizeString = ""; if (totalFilesToDownload > 0) { sizeString += $"{totalFilesToDownload} files, totalling {totalBytesToDownloadAsString} require downloading. "; } if (totalFilesToDelete > 0) { sizeString += $"{totalFilesToDelete} files will be removed."; } SetCurrentAction(sizeString); } //Reset the progress bar Invoke(new MethodInvoker(() => { progressBar1.Visible = false; progressBar1.Value = 0; })); if (settings.AutomaticallyDownloadAfterVerification) { DownloadButton_Click(null, null); } })); }
private void DownloadButton_Click(object sender, EventArgs e) { if (sender != null) { //This is a user call if (verifyTask != null && !verifyTask.IsCompleted) { return; } if (downloadTask != null && !downloadTask.IsCompleted) { return; } } if (filesAreInSync) { return; } if (filesThatRequireUpdate.Count > 0) { downloadTask = Task.Factory.StartNew((Action)(() => { //Reset the progress bar Invoke(new MethodInvoker(() => { progressBar1.Visible = false; progressBar1.Value = 0; progressBar1.Maximum = 1; })); var filesToDownload = filesThatRequireUpdate.Where(f => f.RemoteFileInfo != null); var totalFilesToDownload = filesToDownload.Count(); var totalKilobytesToDownload = filesToDownload.Sum(f => f.RemoteFileInfo.Length) / 1024d; Invoke(new MethodInvoker(() => { progressBar1.Visible = true; progressBar1.ForeColor = SystemColors.Highlight; progressBar1.Maximum = (int)totalKilobytesToDownload; })); int downloadCount = 0; var ftpDownloader = new FtpDownloader(); ftpDownloader.OnProgressChanged += new FtpDownloader.ProgressChangedSignature((bytes) => { var kb = bytes / 1024d; Invoke(new MethodInvoker(() => { progressBar1.Value = (int)kb; })); }); ftpDownloader.OnStartDownload += new FtpDownloader.StartDownloadSignature((pair) => { SetCurrentAction("Downloading " + Path.GetFileName(pair.LocalFilename)); }); ftpDownloader.OnFinishedDownload += new FtpDownloader.FinishedDownloadSignature((pair) => { Interlocked.Increment(ref downloadCount); }); bool allDownloadedSuccessfully = ftpDownloader.DownloadFiles(filesToDownload, settings.DownloadThreads); Invoke(new MethodInvoker(() => { progressBar1.Value = progressBar1.Maximum; })); if (!allDownloadedSuccessfully) { MessageBox.Show("Possible FTP Connection Problem" + Environment.NewLine + "Not all files were downloaded." + Environment.NewLine + "Please verify and try again.", "FTP Download Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } var filesToDelete = filesThatRequireUpdate.Where(f => f.RemoteFileInfo == null).ToList(); filesToDelete.ForEach(pair => { SetCurrentAction("Removing file " + Path.GetDirectoryName(pair.LocalFilename) + @"\" + Path.GetFileNameWithoutExtension(pair.LocalFilename)); File.Delete(pair.LocalFilename); }); SetCurrentAction(string.Format("Finished. Downloaded {0:N0} files.", downloadCount)); filesAreInSync = true; updateStatus.BackgroundImage = Properties.Resources.green_light; //Reset the progress bar Invoke(new MethodInvoker(() => { progressBar1.Visible = false; progressBar1.Value = 0; })); if (settings.AutomaticallyBuildLinksAfterDownload) { Rebuildbutton_Click(null, null); } filesThatRequireUpdate.Clear(); })); } }
public override void GetFilesFromSource(CertificateTask task, IList <CertificateFile> files) { var catalogs = CertificateSourceCatalog.Queryable .Where( c => c.CertificateSource.Id == task.CertificateSource.Id && c.SerialNumber == task.DocumentLine.SerialNumber && c.CatalogProduct.Id == task.DocumentLine.ProductEntity.CatalogProduct.Id) .ToList(); if (catalogs.Count == 0) { task.DocumentLine.CertificateError = "Нет записи в таблице перекодировки"; return; } var tempDowloadDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); TMPDownloadDir = tempDowloadDir; if (!Directory.Exists(tempDowloadDir)) { Directory.CreateDirectory(tempDowloadDir); } var downloader = new FtpDownloader(); try { foreach (var certificateSourceCatalog in catalogs) { var dirName = ExtractFtpDir(certificateSourceCatalog.OriginFilePath); var fileName = ExtractFileName(certificateSourceCatalog.OriginFilePath); var uri = new UriBuilder(task.CertificateSource.LookupUrl) { Path = Path.Combine(dirName, fileName) }.Uri; var downloadFiles = downloader.DownloadedFiles(uri, DateTime.MinValue, tempDowloadDir); if (downloadFiles.Count > 0) { files.Add(new CertificateFile( downloadFiles[0].FileName, certificateSourceCatalog.OriginFilePath, fileName, task.CertificateSource)); } } } finally { if (!String.IsNullOrEmpty(tempDowloadDir) && Directory.Exists(tempDowloadDir) && Directory.GetDirectories(tempDowloadDir).Length == 0 && Directory.GetFiles(tempDowloadDir).Length == 0) { Directory.Delete(tempDowloadDir); } } if (files.Count == 0) { task.DocumentLine.CertificateError = "Файл сертификата не найден на ftp поставщика"; } }
protected void NextButton_Click(object sender, EventArgs e) { ErrorList errors = new ErrorList(); if (StringUtils.IsBlank(FtpHostTextBox.Text)) { errors.Add("Ftp host is required"); } if (NumericUtils.ParseInt32(FtpPortTextBox.Text, 0) == 0) { errors.Add("Ftp host port must be a number"); } if (StringUtils.IsBlank(FtpUsernameTextBox.Text)) { errors.Add("Username is required"); } if (errors.Count > 0) { FeedbackLabel1.SetErrorMessage("Please check the following and try again:", errors); return; } // List of files to upload List <FtpFile> assetFilePaths = new List <FtpFile>(); // Get all of the order items in the current order foreach (OrderItem orderItem in SelectedOrder.OrderItemList) { // Get the order item id int orderItemId = orderItem.OrderItemId.GetValueOrDefault(); // Check if the order item can be downloaded and is in the list of selected order items if (ViewOrders.CanDownload(orderItem) && SelectedOrderItems.Contains(orderItemId)) { // Get the asset Asset asset = orderItem.Asset; // Get the selected order item SelectedOrderItem soi = SelectedOrderItems.Get(orderItemId); // Initialise path and filename to FTP string path, filename; // Check if zip asset files is enabled and we're not doing any kind of transcoding. // If so, we want to FTP the zipped asset file instead, so set the path and filename accordingly. // However, if the zip file doesn't exist, then we want to FTP the original asset instead. if (AssetFileManager.ZipAssetFiles && soi.AssetImageSizeId == 0) { // First get the path to the zipped asset file ZippedAssetFileInfo zippedFileInfo = new ZippedAssetFileInfo(asset); if (zippedFileInfo.FileExists) { // Ensure that a path was returned, and if so, set the filename accordingly path = zippedFileInfo.FilePath; filename = Path.GetFileNameWithoutExtension(asset.Filename) + ".zip"; } else { // Otherwise, the zip file doesn't exist, so get the path to the original // asset file, and set the filename to the asset filename AssetFileInfo info = new AssetFileInfo(asset); path = info.FilePath; filename = asset.Filename; } } else { // Get the file path to the asset AssetFileInfo info = new AssetFileInfo(asset); path = info.FilePath; // For images, get the filepath to the resized image if (AssetTypeChecker.IsImage(asset.FileExtension)) { path = AssetImageManager.GetResizedAssetImage(asset, soi.AssetImageSizeId, soi.DownloadFormat, true); } // Construct the asset filename filename = Path.GetFileNameWithoutExtension(asset.Filename) + Path.GetExtension(path); } // Add the file path to the list FtpFile file = new FtpFile(path, filename); assetFilePaths.Add(file); } } try { // Instantiate FTP downloader FtpDownloader ftpDownloader = new FtpDownloader { BackgroundTransfer = true, Host = FtpHostTextBox.Text.Trim(), Port = NumericUtils.ParseInt32(FtpPortTextBox.Text, 0), PassiveMode = FtpPassiveModeCheckBox.Checked, Username = FtpUsernameTextBox.Text.Trim(), Password = FtpPasswordTextBox.Text.Trim(), RemoteFolder = FtpRemoteFolderTextBox.Text.Trim(), User = CurrentUser }; // Specify files to send to FTP server foreach (FtpFile file in assetFilePaths) { ftpDownloader.Files.Add(file); } // Wire up events ftpDownloader.UploadComplete += new FtpDownloadCompleteEventHandler(NotifyEngine.FtpDownloadComplete); // Go do it! ftpDownloader.Go(); // Log the assets as downloaded foreach (SelectedOrderItem soi in SelectedOrderItems) { OrderItem orderItem = OrderItem.Get(soi.OrderItemId); Asset asset = orderItem.Asset; AuditLogManager.LogAssetAction(asset, CurrentUser, AuditAssetAction.DownloadedAssetFile); AuditLogManager.LogUserAction(CurrentUser, AuditUserAction.DownloadAsset, string.Format("Downloaded AssetId: {0} as part of FTP download to: {1} for OrderId: {2}", asset.AssetId, ftpDownloader.Host, orderItem.OrderId)); } // Lets cookie the settings as well, so we can pre-populate // the form when the user returns to download more assets CookieManager.SetValue("FtpHost", ftpDownloader.Host); CookieManager.SetValue("FtpPort", ftpDownloader.Port); CookieManager.SetValue("FtpPassiveMode", FtpPassiveModeCheckBox.Checked ? "1" : "0"); CookieManager.SetValue("FtpUsername", ftpDownloader.Username); // Update UI FormPanel.Visible = false; SuccessPanel.Visible = true; } catch (FtpDownloadException fdex) { // Remove the error code from the start of the error message string message = Regex.Replace(fdex.Message, @"(\d+\s-\s)", string.Empty); // Display the error to the user FeedbackLabel1.SetErrorMessage("Error downloading assets", message); // Log the error m_Logger.Warn(string.Format("Error downloading files to FTP. User: {0}, Host: {1}. Error: {2}", CurrentUser.FullName, FtpHostTextBox.Text, message), fdex); } }
public void TestMethod1() { FtpDownloader ftp = new FtpDownloader(@"ftp://jacobgudbjerg.dk", "", ""); Assert.IsTrue(ftp.TryPutFile("TestFile2.txt", "Dette er en test\n")); }