可以使用Powershell列出URL目录的内容吗? [英] Can Powershell be used to list the contents of a URL directory?

查看:80
本文介绍了可以使用Powershell列出URL目录的内容吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在FTP服务器上托管了一堆zip文件,这些文件也可以通过HTTP访问.我想做一些类似的事情(gci http://test.com/test/ * .zip)和给我所有存在于网络服务器上的zip文件.

We have a bunch of zip files hosted on an FTP server, which are also accessible via HTTP. I would love to do something like (gci http://test.com/test/ *.zip ) and give me all the zip files which exist on the webserver.

有人知道以一种干净的方式做这样的事情吗?

Does anyone know of a way to do such a thing in a clean way?

TIA

推荐答案

对于invoke-webrequest(PS V3),这很容易

this is quite easy with invoke-webrequest (PS V3)

$r=iwr http://asite.com/test2/ -UseBasicParsing  
$r.Links |?{$_.href -match ".zip"} 

当然,如+ arco444所述,必须启用目录索引

of course as +arco444 states, the directory index must be enable

编辑 要获取最后修改的文件,您将必须解析HTML,这是一个示例(必须将regex适配到您的配置中):

Edit To get the last modified file, you will have to parse the HTML, here is an example (the regex will have to be addapted to your config) :

$col=@()
$link,$date,$size=""
$r=iwr http://asite.com/test2/ 
$r.ParsedHtml.body.getElementsByTagName('TR')|%{ 
    $_.getElementsByTagName('TD') |select -expand innerHTML |%{     
        switch -regex ($_){
            "(.)*zip"{ $link = $_;break}
            "\d{2}-...-\d{4}(.)*"{$date=$_;break}
              "^\d*[KM]"    {$size=$_;break }       
            default{}
        }

    }
        if( $link -and $date -and $size){
        $o=new-object -typename psobject |select  -property "link","date","size"
        $o.link=$link
        $o.date=$date
        $o.size=$size

        $col+=$o
        }
    } 
    $col |select -unique "link","date","size" |sort -desc date |select -last 1

这篇关于可以使用Powershell列出URL目录的内容吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆