windows – powershell:ftp目录列表(脚本帮助)

我正在尝试做一个ftp目录的列表视图.到目前为止观看部分还可以,但我无法操纵我要回来的数据.这是我使用的脚本;
[System.Net.FtpWebRequest]$ftp = [System.Net.WebRequest]::Create("ftp://ftp.microsoft.com/ResKit/y2kfix/alpha/") 
$ftp.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory #Details

$response = $ftp.getresponse() 
$stream = $response.getresponsestream() 

$buffer = new-object System.Byte[] 1024 
$encoding = new-object System.Text.AsciiEncoding 

$outputBuffer = "" 
$foundMore = $false 

## Read all the data available from the stream,writing it to the 
## output buffer when done. 
do 
{ 
    ## Allow data to buffer for a bit 
    start-sleep -m 1000 

    ## Read what data is available 
    $foundmore = $false 
    $stream.ReadTimeout = 1000

    do 
    { 
        try 
        { 
            $read = $stream.Read($buffer,1024) 

            if($read -gt 0) 
            { 
                $foundmore = $true 
                $outputBuffer += ($encoding.GetString($buffer,$read)) 
            } 
        } catch { $foundMore = $false; $read = 0 } 
    } while($read -gt 0) 
} while($foundmore)

$outputBuffer

以下是我为此脚本做出的回应;

PS C:\Users\Toshiba> C:\Apps\@PowerShell\FTPListDirectory.ps1
forfiles.exe
logtime.exe
timeserv
w32time

从那里,我如何处理我要回来的数据.文件信息(名称,创建时间,最后更新等)和其他内容.

我的目标是查看目录中的所有ftp数据,然后我可以下载目录中的所有文件.

任何机会?

首先,您应该检索所有数据

用这个替换方法

$ftp.Method = [System.Net.WebRequestMethods+FTP]::ListDirectoryDetails

没有细节,您只能获得文件名.

要下载文件,我通常使用webclient类

$webclient = New-Object System.Net.WebClient
$webclient.credentials = New-Object System.Net.NetworkCredential("anonymous","anonymous@test.com")
$webclient.downloadfile("ftp://ftp.host.com/file.txt","c:\temp\file.txt")

Downloadfile method of the webclient class

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...