I'm trying to use PowerShell to transfer a compressed file from a share drive to a Linux Host. However, when I use
scp \\path\to\compressed\file.zip user@linuxhost:/tmp
the entire path gets copied to the tmp directory on the Linux Host.
Any idea how I can only transfer the filename.zip without the full path attached to it?
pscp works, but not with the keys I have generated for login without password.
Use the full destination path:
scp \\path\to\compressed\file.zip user@linuxhost:/tmp/file.zip
Assuming you're taking the source file path as user input, you can grab the file name alone with Split-Path
:
function Copy-TmpItem
{
param(
[ValidateScript({Test-Path $_ -PathType Leaf})]
[Parameter(Position = 0, Mandatory = $true)]
[string]$Path
)
$filename = Split-Path $Path -Leaf
scp "'$Path'" "user@linuxhost:'/tmp/$filename'"
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.