137 lines
3.4 KiB
C#
137 lines
3.4 KiB
C#
|
||
using Renci.SshNet;
|
||
using System.Diagnostics;
|
||
using System.Text;
|
||
|
||
try
|
||
{
|
||
|
||
// SCP Settings
|
||
string scpHost = "123.56.94.154";
|
||
string scpUsername = "Administrator";
|
||
string scpPassword = "WHxckj2019";
|
||
|
||
// SCP Connection
|
||
using (var scpClient = new ScpClient(scpHost, scpUsername, scpPassword))
|
||
{
|
||
scpClient.Connect();
|
||
|
||
// Upload File using SCP
|
||
using (var fs = new FileStream(@"D:\favicon.png", FileMode.Open))
|
||
{
|
||
//默认是C盘根目录
|
||
scpClient.Upload(fs, @"/mytest/favicon.png");
|
||
}
|
||
|
||
scpClient.Disconnect();
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
// 创建一个SSH客户端实例
|
||
using (var client = new SshClient("123.56.94.154", "Administrator", "WHxckj2019"))
|
||
{
|
||
// 连接到远程服务器
|
||
client.Connect();
|
||
|
||
//&& ./IRaCIS_Vue_Web.bat
|
||
string command = $@"cd C:\Users\Administrator\VueSourceCode && npm i && npm run build";
|
||
|
||
|
||
using (var cmd = client.CreateCommand(command))
|
||
{
|
||
|
||
Console.WriteLine("开始执行");
|
||
|
||
Console.WriteLine(command);
|
||
|
||
|
||
var output = cmd.Execute();
|
||
|
||
Console.WriteLine(output);
|
||
|
||
|
||
var output3 = cmd.Execute($@"xcopy /Y /Q ""C:\Users\Administrator\VueSourceCode\dist\index.html"" ""D:\Develop\PublishSite\IRaCIS.Vue.Web\dist\""");
|
||
|
||
Console.WriteLine(output);
|
||
|
||
Console.WriteLine("发布成功");
|
||
}
|
||
|
||
|
||
|
||
|
||
// 断开SSH连接
|
||
client.Disconnect();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Console.WriteLine(ex.Message);
|
||
}
|
||
Console.ReadLine();
|
||
|
||
|
||
//// See https://aka.ms/new-console-template for more information
|
||
//using System.Diagnostics;
|
||
//using System.ServiceProcess;
|
||
|
||
//string nginxPath = @"D:\test\EIImageViewerWeb\nginx.exe";
|
||
//string command = $"create EI_Nginx binPath= \"{nginxPath} -p D:\\test\\EIImageViewerWeb\\\" start= auto DisplayName= \"EI_Nginx_DisplayName\"";
|
||
|
||
//try
|
||
//{
|
||
// // 使用SC命令创建Nginx服务
|
||
// using (var process = new System.Diagnostics.Process())
|
||
// {
|
||
// process.StartInfo.FileName = "sc";
|
||
// process.StartInfo.Arguments = command;
|
||
// process.StartInfo.UseShellExecute = false;
|
||
// process.StartInfo.RedirectStandardOutput = true;
|
||
// process.Start();
|
||
// process.WaitForExit();
|
||
|
||
// // 检查服务是否已成功创建
|
||
// if (process.ExitCode != 0)
|
||
// {
|
||
// throw new Exception($"Error creating service: {process.StandardOutput.ReadToEnd()}");
|
||
// }
|
||
// }
|
||
|
||
// // 启动Nginx服务
|
||
// using (var controller = new ServiceController("EI_Nginx"))
|
||
// {
|
||
// controller.Start();
|
||
// }
|
||
|
||
// Console.WriteLine("Nginx service created and started successfully.");
|
||
//}
|
||
//catch (Exception ex)
|
||
//{
|
||
// Console.WriteLine(ex.Message);
|
||
//}
|
||
|
||
//Console.ReadLine();
|
||
|
||
//string currentDir = Directory.GetCurrentDirectory();
|
||
//DirectoryInfo dirInfo = new DirectoryInfo(currentDir);
|
||
|
||
//foreach (var subdir in dirInfo.GetDirectories())
|
||
//{
|
||
// FileInfo[] files = subdir.GetFiles();
|
||
|
||
// foreach (FileInfo file in files)
|
||
// {
|
||
// if (file.Name == "Start.exe")
|
||
// {
|
||
// string startPath = Path.Combine(subdir.FullName, "Start.exe");
|
||
// Process.Start(startPath);
|
||
// return;
|
||
// }
|
||
// }
|
||
//}
|
||
|
||
//Console.WriteLine("当前目录子文件中未找到Start.exe,程序即将退出...");
|
||
//Console.ReadLine(); |