public void PublishToGitFTP(DeploymentModel model) { if (model.AzureDeployment) { var remoteProcess = Process.Start("\"" + gitLocation + "\"", " --git-dir=\"" + fullRepoPath + "\" remote add blog " + model.AzureRepo); if (remoteProcess != null) remoteProcess.WaitForExit(); var pushProcess = Process.Start("\"" + gitLocation + "\"", " --git-dir=\"" + fullRepoPath + "\" push -f blog master"); if (pushProcess != null) pushProcess.WaitForExit(); } else { using (ftp = new FtpConnection(model.FTPServer, model.FTPUsername, model.FTPPassword)) { try { ftp.Open(); ftp.Login(); if (!string.IsNullOrWhiteSpace(model.FTPPath)) { if (!ftp.DirectoryExists(model.FTPPath)) { ftp.CreateDirectory(model.FTPPath); } ftp.SetCurrentDirectory(model.FTPPath); } FtpBlogFiles(snowPublishPath, model.FTPPath); } catch (Exception ex) { } } } }
public FileFilter CopyToFtp(string sourceDirectory, FtpDirectory ftpDir) { using (FtpConnection ftpConnection = new FtpConnection(ftpDir.Host, ftpDir.Port, ftpDir.Username, ftpDir.Password)) { ftpConnection.Open(); ftpConnection.Login(); foreach (WrappedFileSystemInfo fileSystemInfo in GetFilesAndFolders(sourceDirectory)) { if (fileSystemInfo is WrappedDirectoryInfo) { var combinedPath = Path.Combine(ftpDir.BaseDirectory, fileSystemInfo.PathWithoutBaseDirectory); if (!ftpConnection.DirectoryExists(combinedPath)) ftpConnection.CreateDirectory(combinedPath); } else { if (!ftpConnection.DirectoryExists(ftpDir.BaseDirectory)) { ftpConnection.CreateDirectory(ftpDir.BaseDirectory); } var combinedPath = Path.Combine(ftpDir.BaseDirectory, fileSystemInfo.PathWithoutBaseDirectory); var newPath = Path.GetDirectoryName(combinedPath); if (!ftpConnection.DirectoryExists(newPath)) { ftpConnection.CreateDirectory(newPath); } ftpConnection.SetCurrentDirectory(newPath); ftpConnection.PutFile(fileSystemInfo.FullName); } } } return this; }
public void PublishToGitFTP(DeploymentModel model) { if (model.GitDeployment) { Logger.Debug("Executing git add"); var addProcess = new Process(); var addProcessStartInfo = new ProcessStartInfo("\"" + gitLocation + "\"") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, Arguments = " --git-dir=\"" + fullPublishGitPath + "\" --work-tree=\"" + publishGitPath + "\" add -A" }; addProcess.StartInfo = addProcessStartInfo; addProcess.OutputDataReceived += (sender, args) => Logger.Debug(args.Data); addProcess.ErrorDataReceived += (sender, args) => Logger.Debug(args.Data); addProcess.Start(); addProcess.BeginOutputReadLine(); addProcess.BeginErrorReadLine(); addProcess.WaitForExit(); Logger.Debug("git add process to exited"); Logger.Debug("Executing git email config process"); var emailProcess = new Process(); var emailProcessStartInfo = new ProcessStartInfo("\"" + gitLocation + "\"") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, Arguments = " --git-dir=\"" + fullPublishGitPath + "\" --work-tree=\"" + publishGitPath + "\" config user.email \"[email protected]\"" }; emailProcess.StartInfo = emailProcessStartInfo; emailProcess.OutputDataReceived += (sender, args) => Logger.Debug(args.Data); emailProcess.ErrorDataReceived += (sender, args) => Logger.Debug(args.Data); emailProcess.Start(); emailProcess.BeginOutputReadLine(); emailProcess.BeginErrorReadLine(); emailProcess.WaitForExit(); Logger.Debug("git email config process to exited"); Logger.Debug("Executing git name config process"); var userProcess = new Process(); var userProcessStartInfo = new ProcessStartInfo("\"" + gitLocation + "\"") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, Arguments = " --git-dir=\"" + fullPublishGitPath + "\" --work-tree=\"" + publishGitPath + "\" config user.name \"barbato\"" }; userProcess.StartInfo = userProcessStartInfo; userProcess.OutputDataReceived += (sender, args) => Logger.Debug(args.Data); userProcess.ErrorDataReceived += (sender, args) => Logger.Debug(args.Data); userProcess.Start(); userProcess.BeginOutputReadLine(); userProcess.BeginErrorReadLine(); userProcess.WaitForExit(); Logger.Debug("git name config process to exited"); Logger.Debug("Executing git commit"); var commitProcess = new Process(); var commitProcessStartInfo = new ProcessStartInfo("\"" + gitLocation + "\"") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, Arguments = " --git-dir=\"" + fullPublishGitPath + "\" --work-tree=\"" + publishGitPath + "\" commit -a -m \"Static Content Regenerated\"" }; commitProcess.StartInfo = commitProcessStartInfo; commitProcess.OutputDataReceived += (sender, args) => Logger.Debug(args.Data); commitProcess.ErrorDataReceived += (sender, args) => Logger.Debug(args.Data); commitProcess.Start(); commitProcess.BeginOutputReadLine(); commitProcess.BeginErrorReadLine(); commitProcess.WaitForExit(); Logger.Debug("git commit process to exited"); Logger.Debug("Executing git push"); var pushProcess = new Process(); var pushProcessStartInfo = new ProcessStartInfo("\"" + gitLocation + "\"") { RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, Arguments = " --git-dir=\"" + fullPublishGitPath + "\" push -f origin master" }; pushProcess.OutputDataReceived += (sender, args) => Logger.Debug(args.Data); pushProcess.ErrorDataReceived += (sender, args) => Logger.Debug(args.Data); pushProcess.StartInfo = pushProcessStartInfo; pushProcess.Start(); pushProcess.BeginOutputReadLine(); pushProcess.BeginErrorReadLine(); pushProcess.WaitForExit(); Logger.Debug("git push process to exited"); } else { using (ftp = new FtpConnection(model.FTPServer, model.FTPUsername, model.FTPPassword)) { try { ftp.Open(); ftp.Login(); if (!string.IsNullOrWhiteSpace(model.FTPPath)) { var parrentDirectory = String.Format("/{0}", Path.GetDirectoryName(model.FTPPath).Replace(Path.DirectorySeparatorChar, '/')); /* Get name of the directory */ var checkingDirectory = String.Format("{0}", Path.GetFileName(model.FTPPath)).ToLower(); /* Get all child directories info of the parent directory */ var ftpDirectories = ftp.GetDirectories(parrentDirectory); /* check if the given directory exists in the returned result */ var exists = ftpDirectories.Any(d => d.Name.ToLower() == checkingDirectory); if (!exists) { ftp.CreateDirectory(model.FTPPath); } ftp.SetCurrentDirectory(model.FTPPath); } FtpBlogFiles(publishGitPath, model.FTPPath); } catch (Exception ex) { } } } }