使用 Plink 将 .NET 构建文件夹的内容复制到 Ubuntu 服务器 [英] Copying contents of .NET build folder to Ubuntu server using Plink

查看:32
本文介绍了使用 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 将构建文件夹复制到我的服务器中,然后这就是我完全卡住的地方.

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	oserveruild-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	oserveruild-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.您想使用 psftppscp (与 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 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆