在WindOS的PowerShell中有没有等同于webget的命令?
我正在尝试创建一个脚本,从网站下载所有公开可用的文件。我之所以制作定制脚本,是因为我需要将文件存储在特定的目录结构中(取决于名称、类型和大小)。
发布于 2012-10-23 14:16:25
在PowerShell v2中,使用WebClient:
(New-Object System.Net.WebClient).DownloadFile($url, $localFileName) 在v3中,是指Invoke-WebResquest cmdlet:
Invoke-WebRequest -Uri $url -OutFile $localFileName另一种选择是使用Start-BitsTransfer cmdlet:
Start-BitsTransfer -Source $source -Destination $destination发布于 2012-10-23 13:03:34
在PowerShell V3中,您可以使用新的cmdlet Invoke-WebRequest向网站/服务发送http或https请求,例如:
$r = Invoke-WebRequest -URI http://www.bing.com?q=how+many+feet+in+a+mile但是,要专门下载文件,最简单的方法可能是使用.NET API WebClient.DownloadFile(),例如:
$remoteUri = "http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png"
$fileName = "$pwd\logo.png"
$webClient = new-object System.Net.WebClient
$webClient.DownloadFile($remoteUri, $fileName) 发布于 2012-10-23 12:58:56
您可以使用.NET类WebClient来下载文件。
PS > $source = "http://www.unsite.fr/untruc.zip"
PS > $destination = "c:\temp\untruc.zip"
PS >
PS >$wc = New-Object System.Net.WebClient
PS >$wc.DownloadFile($source, $destination)https://stackoverflow.com/questions/13022744
复制相似问题