16 lines
568 B
PowerShell
16 lines
568 B
PowerShell
|
|
param(
|
||
|
|
[Parameter(Mandatory = $true)][string]$Remote,
|
||
|
|
[Parameter(Mandatory = $true)][string]$Local
|
||
|
|
)
|
||
|
|
$ErrorActionPreference = 'Stop'
|
||
|
|
Import-Module Posh-SSH
|
||
|
|
$pw = ConvertTo-SecureString '0' -AsPlainText -Force
|
||
|
|
$cred = New-Object System.Management.Automation.PSCredential('tonycao', $pw)
|
||
|
|
$s = New-SFTPSession -ComputerName 192.168.58.7 -Credential $cred -AcceptKey -Force
|
||
|
|
try {
|
||
|
|
Get-SFTPItem -SessionId $s.SessionId -Path $Remote -Destination $Local -Force
|
||
|
|
Write-Host "OK -> $Local"
|
||
|
|
} finally {
|
||
|
|
Remove-SFTPSession -SessionId $s.SessionId | Out-Null
|
||
|
|
}
|