【问题标题】:Powershell FTP ConnectionPowershell FTP 连接
【发布时间】:2016-07-26 13:08:20
【问题描述】:

我正在使用powershell FTP Client Module 设置 FTP 连接以检索一些文件。

我知道我可以通过这种方式捕获命令的输出:

$output = (command) | Out-String

我想将-Verbose 属性的输出重定向到一个变量中。我正在做这样的事情,但是无法创建 FTP 连接,我的脚本就停止了。

$output1 = (Set-FTPConnection -Server $ftp_server -Credentials $mycreds -Session $session)
$output2 = (
    Get-FTPChildItem -Path $ftp_path -Session $session -Verbose | % {
        $ftpFile = "ftpPathIn/$($_.Name)"
        Get-FTPItem -Path $ftpFile -LocalPath $PathToFile  -Overwrite -Session $session -Verbose
    } ) | Out-String

PS:没有尝试重定向变量中的输出,脚本运行得很好。所以我怀疑错误在于我尝试在$output 中重定向输出的方式。 如何重定向变量 $output 中的输出?

【问题讨论】:

    标签: powershell ftp


    【解决方案1】:

    你可以试试这样的:

    $output2 = $(
        Get-FTPChildItem -Path $ftp_path -Session $session -Verbose | % {
            $ftpFile = "ftpPathIn/$($_.Name)"
            Get-FTPItem -Path $ftpFile -LocalPath $PathToFile  -Overwrite -Session $session -Verbose
        } ) 4>&1
    

    有关流重定向语法的说明,请参阅Get-Help about_Redirection

    猜你喜欢
    • 2018-06-18
    • 2017-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-28
    相关资源
    最近更新 更多