2009-03-03 8 views
3

Gibt es einen Windows-Befehl zum Kopieren oder Herunterladen von Dateien von einer http-URL in das Dateisystem? Ich habe mit Kopie, xcopy und robocopy versucht, und sie scheinen http URLs nicht zu stützen.Windows-Datei kopieren mit http

Antwort

7

Sie können hierzu ein Powershell-Skript verwenden.
Get-Web http://www.msn.com/ -toFile www.msn.com.html

function Get-Web($url, 
    [switch]$self, 
    $credential, 
    $toFile, 
    [switch]$bytes) 
{ 
    #.Synopsis 
    # Downloads a file from the web 
    #.Description 
    # Uses System.Net.Webclient (not the browser) to download data 
    # from the web. 
    #.Parameter self 
    # Uses the default credentials when downloading that page (for downloading intranet pages) 
    #.Parameter credential 
    # The credentials to use to download the web data 
    #.Parameter url 
    # The page to download (e.g. www.msn.com)  
    #.Parameter toFile 
    # The file to save the web data to 
    #.Parameter bytes 
    # Download the data as bytes 
    #.Example 
    # # Downloads www.live.com and outputs it as a string 
    # Get-Web http://www.live.com/ 
    #.Example 
    # # Downloads www.live.com and saves it to a file 
    # Get-Web http://wwww.msn.com/ -toFile www.msn.com.html 
    $webclient = New-Object Net.Webclient 
    if ($credential) { 
     $webClient.Credential = $credential 
    } 
    if ($self) { 
     $webClient.UseDefaultCredentials = $true 
    } 
    if ($toFile) { 
     if (-not "$toFile".Contains(":")) { 
      $toFile = Join-Path $pwd $toFile 
     } 
     $webClient.DownloadFile($url, $toFile) 
    } else { 
     if ($bytes) { 
      $webClient.DownloadData($url) 
     } else { 
      $webClient.DownloadString($url) 
     } 
    } 
} 

Quelle http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/01/microcode-powershell-scripting-tricks-scripting-the-web-part-1-get-web.aspx

+0

Großartig! Ich habe die SSH-Cmd in Powershell geändert und es hat gut funktioniert. – Pablote

0

Ich kann mich an kein Befehlszeilenprogramm dafür erinnern. Vielleicht können Sie etwas ähnliches mit JavaScript (mit WinHttpRequest) und läuft es so implementieren:

wscript your_script.js 

Oder nur msys mit wget installieren.

4

Ich kenne keine Befehle unter Windows, die das können, aber ich lade immer GNU wget unter Windows für diese und ähnliche Zwecke.

1

cURL in den Sinn kommt.

curl -o homepage.html http://www.apptranslator.com/ 

Dieser Befehl lädt die Seite herunter und speichert sie in der Datei homepage.html. Tausende Optionen verfügbar.

0

Gerade verwenden Win32 API (1 Zeile Code in C ...)

+1

kannst du welche api posten? –

1

Verwenden BITSAdmin Tool (BITSAdmin ist ein Befehlszeilenprogramm auf Windows)

Beispiel:

bitsadmin /transfer "Download_Job" /download /priority high "http://www.sourceWebSite.com/file.zip" "C:\destination\file.zip" 

wo, Download_Job - Alle relevanten Jobnamen, die Sie wollen