powershell批量拷贝数据
用了个临时密码摆脚本里了,不推荐
点击查看代码
$remoteUser = "amery"
$remoteIP = "172.20.3.154"
$password = "templatePASS"
$remoteBasePath = "/home/amery/data/m15"
$localBasePath = "E:\ARfiles"
if (!(Test-Path $localBasePath)) {
New-Item -ItemType Directory -Path $localBasePath
}
$plinkCmd = "plink.exe -pw $password $remoteUser@$remoteIP find $remoteBasePath -type f -name '*.ar'"
$arFileList = Invoke-Expression $plinkCmd
foreach ($remoteFile in $arFileList) {
$relativePath = $remoteFile -replace "^$remoteBasePath/", ""
$localFilePath = Join-Path $localBasePath $relativePath
$localDir = Split-Path $localFilePath
if (!(Test-Path $localDir)) {
New-Item -ItemType Directory -Path $localDir -Force | Out-Null
}
$pscpCmd = "pscp.exe -pw $password ${remoteUser}@${remoteIP}:`"$remoteFile`" `"$localFilePath`""
Invoke-Expression $pscpCmd
}

浙公网安备 33010602011771号