【发布时间】:2019-09-17 21:12:44
【问题描述】:
我的 Ubuntu 虚拟机上有一个 node.js 脚本,它在完成执行后会生成一个 Json 文件。到目前为止,我可以使用以下代码从 .NET Core 控制台应用程序(使用 Visual Studio 2019)执行此脚本:
string subscriptionId = "mySubscriptionId";
string clientId = "myclientId";
string tenantId = "myTenantId";
string clientSecret = "myClientSecret";
var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientId, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud);
var azure = Azure.Configure().Authenticate(credentials).WithSubscription(subscriptionId);
var vm = await azure.VirtualMachines.GetByResourceGroupAsync("MyAzureRg", "MyUbuntuVm");
string cmd1 = "#!/bin/bash";
string cmd2 = "cd /home/Username/myapp/";
string cmd3 = "xvfb-run nodejs myNodeScript.js";
List<string> commands = new List<string>{cmd1,cmd2,cmd3};
Console.WriteLine("Executing shell script");
await vm.RunShellScriptAsync(commands, null);
Console.WriteLine("Script executed!");
然后我使用 PuTTY 和 SSH 连接到 Ubuntu VM,并且可以确认 Json 已在路径 /home/Username/myapp/ 中正确创建。但是,我的问题是如何将其中的内容取回(读取或下载)到 .NET Core 应用程序?
【问题讨论】:
标签: c# azure ubuntu .net-core virtual-machine