本文介绍了使用Plink将.NET构建文件夹的内容复制到Ubuntu服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在PowerShell中构建一个预部署脚本,该脚本创建.NET Core Web Api应用程序的生产版本,然后通过SSH密钥SSH到我的Ubuntu Digital Ocean Droplet中。

I'm building a pre-deploy script in PowerShell that creates a production build of my .NET Core Web Api application and then SSHs into my Ubuntu Digital Ocean Droplet via SSH key.

我目前处于创建构建的阶段,请使用 Copy-Item 复制构建文件夹, SSH进入我的服务器,然后这就是我完全卡住的地方。

I'm currently at a stage where I create the build, copy the build folder using Copy-Item, SSH into my server and then this is where I'm completely stuck.

我知道我可以从PowerShell脚本运行BASH命令,因为我已经尝试了一些基本操作,例如创建和删除目录,我可以 cd 进入和退出目录。我尝试将复制的.NET构建文件夹作为变量存储在内存中:
$ build = Copy-Item -Path $ projectBuildPath -Recurse ,然后发现做到这一点(真可惜,那真是太酷了),然后通过p-link cli打开到我服务器的会话,就像这样:

I know that I can run BASH commands from my PowerShell script because I've tried some basic operations like creating and deleting a directory, I can cd in and out of directories. I've tried storing the copied .NET build folder in memory as a variable:$build = Copy-Item -Path $projectBuildPath -Recurse and then found out that this can't be done (shame really, that would have been cool) and then opening a session to my server via p-link cli like so:

plink.exe -ssh -i $SSHKeyLocation $linuxRemoteHost "cd path\to\server\build-folder && paste ${build}"

但是同样,由于您无法将复制的目录存储在内存中,因此失败了。

But again because you can't store copied directories in memory, this failed.

我的PowerShell脚本如下:

My PowerShell script looks like this:

$projectRootDir
$projectBuildPath
$linuxRemoteHost
$SSHKeyLocation

Set-Location $projectRootDir
Write-Host "Building .NET application..."

dotnet publish --configuration Release --verbosity normal

Write-Host "Built Successfully..."
Write-Host "Copying project build files"

$build = Copy-Item -Path $projectBuildPath -Recurse
# fails, for obvious reasons

Write-Host "Remoting into MusicPortal Server..."

plink.exe -ssh -i $SSHKeyLocation $linuxRemoteHost "cd path\to\server\build-folder && paste ${build}"
# SSH Connection successful, paste command fails

Write-Host "Remote successfull, transfering build files..."

exit 0

要成功将复制的目录粘贴到服务器上,我该怎么做?我对PowerShell和SSH非常了解。

What should I do in order to successfully paste the copied directory to my server? I'm such a noob with PowerShell and SSH.

推荐答案

尝试使用 plink很奇怪将文件上传到服务器。由于您没有给出任何特定原因,所以为什么要使用 plink ,我假设这是一个错误。

It's quite strange to try to use plink to upload files to a server. As you didn't give any particular reason, why you want to use plink, I'm assuming that it's a mistake.

您不想使用 plink 。您要使用或(与 plink 属于同一PuTTY软件包的一部分)。

You do not want to use plink. You want to use psftp or pscp (both part of the same PuTTY package as plink).

pscp -r -i $SSHKeyLocation $projectBuildPath $linuxRemoteHost:/path/to/server/build-folder/

这篇关于使用Plink将.NET构建文件夹的内容复制到Ubuntu服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-25 12:57