/// <summary> /// Executes the specified result. /// </summary> /// <param name="result">The result.</param> /// <returns></returns> /// <remarks></remarks> protected override bool Execute(IIntegrationResult result) { var relativeLocalFolder = result.BaseFromWorkingDirectory(this.LocalFolderName); result.BuildProgressInformation.SignalStartRunTask(!string.IsNullOrEmpty(Description) ? Description : GetDescription(relativeLocalFolder)); string remoteFolder = FtpFolderName; FtpLib ftp = new FtpLib(this, result.BuildProgressInformation); try { ftp.LogIn(ServerName, UserName, Password, UseActiveConnectionMode); ftp.TimeDifference = new TimeSpan(TimeDifference, 0, 0); if (!FtpFolderName.StartsWith("/")) { remoteFolder = System.IO.Path.Combine(ftp.CurrentWorkingFolder(), FtpFolderName); } if (Action == FtpAction.UploadFolder) { Log.Debug("Uploading {0} to {1}, recursive : {2}", relativeLocalFolder, remoteFolder, RecursiveCopy); ftp.UploadFolder(remoteFolder, relativeLocalFolder, RecursiveCopy); } if (Action == FtpAction.DownloadFolder) { Log.Debug("Downloading {0} to {1}, recursive : {2}", remoteFolder, relativeLocalFolder, RecursiveCopy); ftp.DownloadFolder(relativeLocalFolder, remoteFolder, RecursiveCopy); } } catch (Exception ex) { Log.Error(ex); // try to disconnect in a proper way on getting an error try { // swallow exception on disconnect to keep the original error if (ftp.IsConnected()) { ftp.DisConnect(); } } catch { } Log.Info("throwing"); throw; } return(true); }
/// <summary> /// Gets the modifications. /// </summary> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <returns></returns> /// <remarks></remarks> public override Modification[] GetModifications(IIntegrationResult from, IIntegrationResult to) { ftp = new FtpLib(to.BuildProgressInformation); string remoteFolder = FtpFolderName; ftp.LogIn(ServerName, UserName, Password.PrivateValue, UseActiveConnectionMode); if (!FtpFolderName.StartsWith("/")) { remoteFolder = System.IO.Path.Combine(ftp.CurrentWorkingFolder(), FtpFolderName); } Modification[] mods = ftp.ListNewOrUpdatedFilesAtFtpSite(LocalFolderName, remoteFolder, RecursiveCopy); ftp.DisConnect(); return(mods); }
/// <summary> /// Gets the source. /// </summary> /// <param name="result">The result.</param> /// <remarks></remarks> public override void GetSource(IIntegrationResult result) { Util.Log.Info(result.HasModifications().ToString(CultureInfo.CurrentCulture)); ftp = new FtpLib(result.BuildProgressInformation); string remoteFolder = FtpFolderName; ftp.LogIn(ServerName, UserName, Password.PrivateValue, UseActiveConnectionMode); if (!FtpFolderName.StartsWith("/")) { remoteFolder = System.IO.Path.Combine(ftp.CurrentWorkingFolder(), FtpFolderName); } ftp.DownloadFolder(LocalFolderName, remoteFolder, RecursiveCopy); ftp.DisConnect(); }