Powershell 从SFTP目录获取所有文件,扩展名为的子目录不工作。
我使用下面的代码来获取文件,它对目录有效,但我也希望遍历子目录,当我放置-递归时,它停止工作Powershell 从SFTP目录获取所有文件,扩展名为的子目录不工作。,powershell,powershell-3.0,Powershell,Powershell 3.0,我使用下面的代码来获取文件,它对目录有效,但我也希望遍历子目录,当我放置-递归时,它停止工作 Import-Module –Name "C:\Users\Administrator\Documents\WindowsPowerShell\Modules\Posh-SSH" -Verbose $passwordTest = "Password" $securePasswordTest = ConvertTo-SecureString $passwordTest -AsPlainText -For
Import-Module –Name "C:\Users\Administrator\Documents\WindowsPowerShell\Modules\Posh-SSH" -Verbose
$passwordTest = "Password"
$securePasswordTest = ConvertTo-SecureString $passwordTest -AsPlainText -Force
$credentialsTest = New-Object System.Management.Automation.PSCredential ("USername", $securePasswordTest)
$sessionTest = New-SFTPSession -ComputerName SFTP -Credential $credentialsTest -AcceptKey
$sourceTest = "/u01/G"
$destinationTest= "F:\SourceOLTP\"
Get-SFTPChildItem $sessionTest -Path $sourceTest | ForEach-Object{
if ($_.Fullname -like '*.csv')
{
Get-SFTPFile $sessionTest -RemoteFile $_.FullName -LocalPath $destinationTest -Overwrite
}
write-output $_.FullName
}
Remove-SFTPSession $sessionTest -Verbose
Get SFTPChildItem
上的递归开关似乎是-Recursive
来源:谢谢你的建议,但当我应用递归时,它会给我一个错误。Get-SFTPChildItem:找不到与参数名称“Recursive”匹配的参数。但是当您执行
-递归时,该错误不会出现?当您使用-Recurse
时,它以什么方式停止工作?当我使用-Recurse时,它给出了不同的错误。找不到接受argumentTryGet-SFTPChildItem-SFTPSession$sessionTest-Path$sourceTest-Recurse |…