public static void UploadFolder(FtpParameters parameters, string targetFolder, string sourceFolder) { using (var ftp = new Ftp()) { long currentPercentage = 0; ftp.Connect(parameters.Address, parameters.Port); ftp.Login(parameters.UserName, parameters.Password); ftp.Progress += (sender, args) => { if (currentPercentage < args.Percentage) { Logger.LogInfo("Uploaded {0} of {1} bytes {2}%", args.TotalBytesTransferred, args.TotalBytesToTransfer, args.Percentage); currentPercentage = args.Percentage; } }; if (!ftp.FolderExists(targetFolder)) { ftp.CreateFolder(targetFolder); } Logger.LogInfo("Uploading from {0} to {1}...", sourceFolder, targetFolder); ftp.UploadFiles(targetFolder, sourceFolder); Logger.LogInfo("Move from {0} to {1}...Complete", sourceFolder, targetFolder); } }
public override void Create() { if (Exists()) { throw new FileAlreadyExistException(); } Client.CreateFolder(Path.PathStr); }
/// <summary> /// Adds a directory to FTP /// </summary> /// <param name="opts">The options</param> /// <returns>The result</returns> int FTPAddDirectory(FTPAddDirectoryOptions opts) { using (Ftp ftp = new Ftp()) { try { ftp.Connect(Properties.Settings.Default.FTPServer); ftp.Login(Properties.Settings.Default.FTPUsername, CommandLineSecurity.ToInsecureString(CommandLineSecurity.DecryptString(Properties.Settings.Default.FTPPassword))); } catch (Exception ex) { MessageBox.Show(new Form(), ex.Message, "Mist of Time Publisher", MessageBoxButtons.OK, MessageBoxIcon.Error); return(1); } try { if (!ftp.FolderExists("cdn")) { ftp.CreateFolder("cdn"); } } catch (Exception ex) { MessageBox.Show(new Form(), ex.Message, "Mist of Time Publisher", MessageBoxButtons.OK, MessageBoxIcon.Error); return(1); } try { if (!opts.ServerPath.StartsWith("/")) { opts.ServerPath = "/" + opts.ServerPath; } ftp.CreateFolder("cdn" + opts.ServerPath); } catch (Exception) { return(2); } } return(0); }
public void CreerDossier(string leNmDossierACreer, ElementFolder leDossierDistant) { using (_monFtp = new Ftp()) { _monFtp.Connect(_maConfig.Host, _maConfig.Port); _monFtp.Login(_maConfig.Login, _maConfig.MotDePass); string resteChemin = MethodesGlobales.GetCheminServerSansRacinne(leDossierDistant.GetPath(), _maConfig.GetUriChaine()); _monFtp.ChangeFolder(resteChemin); _monFtp.CreateFolder(leNmDossierACreer); _monFtp.Close(); } }
public void UploadDossier(ElementFolder dossierLocal, ElementFolder dossierDistant) { using (_monFtp = new Ftp()) { _monFtp.Connect(_maConfig.Host, _maConfig.Port); _monFtp.Login(_maConfig.Login, _maConfig.MotDePass); string resteChemin = MethodesGlobales.GetCheminServerSansRacinne(dossierDistant.GetPath(), _maConfig.GetUriChaine()); _monFtp.CreateFolder(MethodesGlobales.GetCheminDossierUploadSurServeur(resteChemin, dossierLocal.GetName())); LocalSearchOptions uneLocalSearchOption = new LocalSearchOptions("*", true); _monFtp.UploadFiles(MethodesGlobales.GetCheminDossierUploadSurServeur(resteChemin, dossierLocal.GetName()), dossierLocal.GetPath(), uneLocalSearchOption); _monFtp.Close(); } }
/// <summary> /// Adds a file to FTP /// </summary> /// <param name="opts">The options</param> /// <returns>The result</returns> int FTPAddFile(FTPAddFileOptions opts) { using (Ftp ftp = new Ftp()) { try { ftp.Connect(Properties.Settings.Default.FTPServer); ftp.Login(Properties.Settings.Default.FTPUsername, CommandLineSecurity.ToInsecureString(CommandLineSecurity.DecryptString(Properties.Settings.Default.FTPPassword))); } catch (Exception ex) { MessageBox.Show(new Form(), ex.Message, "Mist of Time Publisher", MessageBoxButtons.OK, MessageBoxIcon.Error); return(1); } try { if (!ftp.FolderExists("cdn")) { ftp.CreateFolder("cdn"); } } catch (Exception ex) { MessageBox.Show(new Form(), ex.Message, "Mist of Time Publisher", MessageBoxButtons.OK, MessageBoxIcon.Error); return(1); } try { if (!opts.ServerPath.StartsWith("/")) { opts.ServerPath = "/" + opts.ServerPath; } ftp.Upload("cdn" + opts.ServerPath, opts.LocalPath); string oldPath = Path.GetDirectoryName("cdn" + opts.ServerPath).Replace('\\', '/') + "/FtpTrial-" + Path.GetFileName("cdn" + opts.ServerPath); if (ftp.FileExists(oldPath)) { ftp.Rename(oldPath, "cdn" + opts.ServerPath); } } catch (Exception) { return(2); } } return(0); }
public bool Process( string uploadPath, ConnectionSettings connection) { var processLog = new StringBuilder(); var uploadGroupPath = Path.Combine(uploadPath, _webLocationFolderName); if (!Directory.Exists(uploadGroupPath)) { Directory.CreateDirectory(uploadGroupPath); } var uploadSitePath = Path.Combine(uploadGroupPath, Path.GetFileName(_sourcePath)); var currentFolder = _sourcePath; bool completedSuccessFully; try { processLog.AppendLine(String.Format("iSpring tune process started at folder {0}", _sourcePath)); var webContentPath = Path.Combine(_sourcePath, WebContentFolderName); var convertedFolderName = (WebContentFolderName.Replace(" ", " ") .Replace(" ", " ") .Replace(" ", "_") .Replace("(", "") .Replace(")", "") + _id) .ToLower(); var destinationFolderPath = Path.Combine(_sourcePath, convertedFolderName); if (!String.Equals(webContentPath, destinationFolderPath, StringComparison.OrdinalIgnoreCase)) { try { Directory.Move(webContentPath, destinationFolderPath); } catch (Exception ex) { throw new UnauthorizedAccessException(String.Format("Error while change folder name with {0}{1}{2}", convertedFolderName, ex.Message, Environment.NewLine)); } } processLog.AppendLine(String.Format("Folder name changed with {0}", convertedFolderName)); var dataFolderPath = Path.Combine(destinationFolderPath, DataFolderName); if (!Directory.Exists(dataFolderPath)) { throw new FileNotFoundException(String.Format("Site Data folder {0} not found", dataFolderPath)); } File.WriteAllText(Path.Combine(dataFolderPath, JqueryFileName), Properties.Resources.JQueryFileContent); processLog.AppendLine(String.Format("File added {0}", JqueryFileName)); File.WriteAllText(Path.Combine(dataFolderPath, JsonFileName), Properties.Resources.JSonFileContent); processLog.AppendLine(String.Format("File added {0}", JsonFileName)); File.WriteAllText(Path.Combine(dataFolderPath, MetroNotificationScriptFileName), Properties.Resources.MetroNotificationScriptFileContent); processLog.AppendLine(String.Format("File added {0}", MetroNotificationScriptFileName)); File.WriteAllText(Path.Combine(dataFolderPath, MetroNotificationStyleFileName), Properties.Resources.MetroNotificationStyleFileContent); processLog.AppendLine(String.Format("File added {0}", MetroNotificationStyleFileName)); File.WriteAllText(Path.Combine(dataFolderPath, FontAwesomeStyleFileName), Properties.Resources.FontAwesomeStyleContent); processLog.AppendLine(String.Format("File added {0}", FontAwesomeStyleFileName)); var activityRegularFileContent = Properties.Resources.ActivityRegularFileContent; activityRegularFileContent = activityRegularFileContent.Replace(SitePathPlaceHolder, connection.Url); activityRegularFileContent = activityRegularFileContent.Replace(EmailPlaceHolder, String.Join(";", _emails)); activityRegularFileContent = activityRegularFileContent.Replace(AdvertiserPlaceHolder, _advertiserName.Replace("'", @"\'")); File.WriteAllText(Path.Combine(dataFolderPath, ActivityRegularFileName), activityRegularFileContent); processLog.AppendLine(String.Format("File added {0}", ActivityRegularFileName)); var activityLoginFileContent = Properties.Resources.ActivityLoginFileContent; activityLoginFileContent = activityLoginFileContent.Replace(AdvertiserPlaceHolder, _advertiserName.Replace("'", @"\'")); activityLoginFileContent = activityLoginFileContent.Replace(FileNamePlaceHolder, String.Format("{0}.pptx", Name)); File.WriteAllText(Path.Combine(dataFolderPath, ActivityLoginFileName), activityLoginFileContent); processLog.AppendLine(String.Format("File added {0}", ActivityLoginFileName)); File.WriteAllText(Path.Combine(destinationFolderPath, LoginIndexFileName), Properties.Resources.LoginIndexFileContent); processLog.AppendLine(String.Format("File added {0}", LoginIndexFileName)); var originalIndexFilePath = Path.Combine(destinationFolderPath, OriginalIndexFileName); var publicIndexFilePath = Path.Combine(destinationFolderPath, PublicIndexFileName); if (!File.Exists(originalIndexFilePath)) { throw new FileNotFoundException(String.Format("Site Index file not found")); } var indexFileContent = File.ReadAllText(originalIndexFilePath); File.Delete(originalIndexFilePath); var originalHeadContent = String.Empty; var matches = Regex.Matches(indexFileContent, @"<head>([.\S+\n\r\s]*?)<\/head>"); if (matches.Count > 0 && matches[0].Groups.Count > 1) { originalHeadContent = matches[0].Groups[1].Value; } if (!String.IsNullOrEmpty(originalHeadContent)) { if (!originalHeadContent.Contains(Properties.Resources.PublicIndexScriptIncludePart)) { var modifiedHeadContent = String.Format("{0}{2}{1}", originalHeadContent, Properties.Resources.PublicIndexScriptIncludePart, Environment.NewLine); File.WriteAllText(publicIndexFilePath, indexFileContent.Replace(originalHeadContent, modifiedHeadContent)); } } processLog.AppendLine("Web Folder html file new code added"); Directory.Move(_sourcePath, uploadSitePath); currentFolder = uploadSitePath; processLog.AppendLine(String.Format("CWL PACK Moved to Upload folder ({0})", uploadSitePath)); using (var ftp = new Ftp()) { ftp.Connect(connection.FtpUrl); ftp.Login(connection.Login, connection.Password); ftp.ChangeFolder(FtpRootFolder); ftp.CreateFolder(_webLocationFolderName); ftp.ChangeFolder(_webLocationFolderName); ftp.CreateFolder(convertedFolderName); ftp.UploadFiles(convertedFolderName, Path.Combine(uploadSitePath, convertedFolderName)); ftp.Close(); } processLog.AppendLine("Web Folder uploaded with web services to clientweblink.com"); OutlookHelper.Instance.SendMessage( String.Format("HTML5 presentation ready for {0}", _advertiserName), String.Format("Your HTML5 Web Link is ready for: {0}{3}{3}" + "Public URL{3}{1}{3}{3}" + "Client Login URL{3}{2}{3}{3}" + "*Please Note:{3}You will receive a confirmation email each time someone views this presentation.{3}{3}{3}" + "If you have any technical issues with your HTML5 web link, then email:{3}[email protected]", _advertiserName, String.Format("{0}/{1}/{2}/{3}/{4}", connection.Url, SiteRootFolder, _webLocationFolderName, convertedFolderName, PublicIndexFileName), String.Format("{0}/{1}/{2}/{3}/{4}", connection.Url, SiteRootFolder, _webLocationFolderName, convertedFolderName, LoginIndexFileName), Environment.NewLine), _emails); processLog.AppendLine(String.Format("Confirmation email with URL sent to {0}", String.Join(";", _emails))); processLog.AppendLine("iSpring tune process completed successfully"); completedSuccessFully = true; } catch (Exception ex) { processLog.AppendLine("iSpring tune process completed unsuccessfully"); processLog.AppendLine(ex.Message); processLog.AppendLine(ex.StackTrace); completedSuccessFully = false; } finally { var logFilePath = Path.Combine(currentFolder, LogFileName); File.WriteAllText(logFilePath, processLog.ToString()); } return(completedSuccessFully); }