获取SFTP目录和扩展名子目录中的所有文件不起作用。

时间:2017-08-07 20:29:09

标签: powershell powershell-v3.0

我正在使用以下代码来获取文件,它适用于目录,但我也想遍历子目录,当我把-recurse它停止工作时。

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

1 个答案:

答案 0 :(得分:2)

Get-SFTPChildItem上的递归开关似乎是-Recursive

来源:https://github.com/darkoperator/Posh-SSH/blob/master/docs/Get-SFTPChildItem.md