windows – powershell:ftp目录列表(脚本帮助)
发布时间:2020-12-14 01:47:50 所属栏目:Windows 来源:网络整理
导读:我正在尝试做一个ftp目录的列表视图.到目前为止观看部分还可以,但我无法操纵我要回来的数据.这是我使用的脚本; [System.Net.FtpWebRequest]$ftp = [System.Net.WebRequest]::Create("ftp://ftp.microsoft.com/ResKit/y2kfix/alpha/") $ftp.Method = [System.
我正在尝试做一个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:UsersToshiba> C:Apps@PowerShellFTPListDirectory.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:tempfile.txt") Downloadfile method of the webclient class (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读