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.
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.
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.
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
What should I do in order to successfully paste the copied directory to my server? I'm such a noob with PowerShell and SSH.
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.
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/
来源:https://stackoverflow.com/questions/57794049/copying-contents-of-net-build-folder-to-ubuntu-server-using-plink