2012-07-15 3 views
1

나는이 유용한 vbscript on the web을 (를) 다운로드하여 파일 다운로드를 자동화합니다.vbScript 자동 확장명으로 파일 다운로드

function download(sFileURL, sLocation) 

'create xmlhttp object 
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP") 

'get the remote file 
objXMLHTTP.open "GET", sFileURL, false 

'send the request 
objXMLHTTP.send() 

'wait until the data has downloaded successfully 
do until objXMLHTTP.Status = 200 : wscript.sleep(1000) : loop 

'if the data has downloaded sucessfully 
If objXMLHTTP.Status = 200 Then 

     'create binary stream object 
    Set objADOStream = CreateObject("ADODB.Stream") 
    objADOStream.Open 

     'adTypeBinary 
    objADOStream.Type = 1 
    objADOStream.Write objXMLHTTP.ResponseBody 

     'Set the stream position to the start 
    objADOStream.Position = 0  

     'create file system object to allow the script to check for an existing file 
     Set objFSO = Createobject("Scripting.FileSystemObject") 

     'check if the file exists, if it exists then delete it 
    If objFSO.Fileexists(sLocation) Then objFSO.DeleteFile sLocation 

     'destroy file system object 
    Set objFSO = Nothing 

     'save the ado stream to a file 
    objADOStream.SaveToFile sLocation 

     'close the ado stream 
    objADOStream.Close 

    'destroy the ado stream object 
    Set objADOStream = Nothing 

'end object downloaded successfully 
End if 

'destroy xml http object 
Set objXMLHTTP = Nothing 

End function 

download "http://remote-location-of-file", "C:\name-of-file-and-extension" 

일부 웹 위치의 URL과, 예를 들어 다운로드 *이 .exe 파일을 구문 분석하도록 강제 할 수있는 방법이 있나요? 다음과 같이하십시오 :

URL: http://examplesite.com/files/ 

file0001.exe 

시간이 지남에 이름이 변경되는 파일이 있기 때문에. 확장명은 .exe입니다.

나는 http와 ftp 프로토콜을 사용할 수 있으며 ftp는 인증이 없다 (무료).

답변

0

해당 사이트에서 파일 찾아보기를 사용 설정하는 것이 가능하고 거의 사용하지 않는 경우에만 가능합니다. 파일 이름을 구문 분석하기 위해 파일 이름이 나열된 URL이 필요합니다. 그런 옵션이있는 wget http://users.ugent.be/~bpuype/wget/과 같은 도구를 사용하는 것이 좋습니다. 또한 vbscript는 그러한 작업을위한 좋은 선택이 아닙니다. 처음부터 시작한다면 Ruby와 더 잘 어울릴 것입니다.

문제의 URL을 게시하면 도움이 될 수 있습니다.

관련 문제