' File Downloader! v1.0 ' (C) 2008 Innova and Kristopher Windsor #include once "windows.bi" Sub crash (Byref details As String = "") Print "Error! " & details Print "Press [Spacebar] to continue, else to quit..." While Len(Inkey()): Sleep(10, 1): Wend Sleep() If Inkey() <> " " Then System() End Sub Function getclipboard () As String Dim As Zstring Ptr s_ptr Dim As HANDLE hglb Dim As String s = "" If (IsClipboardFormatAvailable(CF_TEXT) = 0) Then Return "" If OpenClipboard( NULL ) <> 0 Then hglb = GetClipboardData(cf_text) s_ptr = GlobalLock(hglb) If (s_ptr <> NULL) Then s = *s_ptr GlobalUnlock(hglb) End If CloseClipboard() End If Return s End Function Function getfilecontents (Byref file As String) As String Dim As Integer ff = Freefile Dim As String text, l If Open(file For Input As #ff) Then crash("Cannot parse " & file) While Not Eof(ff) Line Input #ff, l text += l & Chr(13, 10) Wend Close #ff Return text End Function Function downloadfile (Byref url As String, Byref target As String = Curdir) As Integer Dim As Any Ptr library Dim URLDownloadToFile As Function (Byval pCaller As Any Ptr, Byval szURL As String, _ Byval szFileName As String, Byval dwResv As Uinteger, Byval lpfnCB As Any Ptr) As Integer Print "Downloading file " & target library = Dylibload("urlmon") If library = 0 Then Return true URLDownloadToFile = Dylibsymbol(library, "URLDownloadToFileA") If URLDownloadToFile = 0 Then Dylibfree(library): Return true If URLDownloadToFile(0, url, target, 0, 0) Then Dylibfree(library): Return true Dylibfree(library) Return false End Function Sub downloadfolder (Byref url As String, Byref path As String = Curdir) Dim As Integer p1, p2, p3, p4, valid Dim As String index, l, target Print "Downloading folder " & path If Mkdir(path) Then crash("Cannot create the folder " & path) If downloadfile(url, path & "index.html") Then crash("Cannot download index for " & path) index = getfilecontents(path & "index.html") p1 = 0 Do p2 = p1 p1 = Instr(p1 + 1, index, Chr(10)) If p1 = 0 Then p1 = Len(index) + 1 l = Trim(Mid(index, p2 + 1, p1 - p2 - 1), Any Chr(9, 10, 13, 32)) If Instr(Ucase(l), "INDEX OF") > 0 Then valid = true 'ignore web pages If Instr(Ucase(l), " 0 And Instr(Ucase(l), "HREF=") > 0 And valid And _ Instr(Ucase(l), "PARENT DIRECTORY") = 0 And Instr(Ucase(l), "LAST MODIFIED") = 0 Then p3 = Instr(Ucase(l), "HREF=") + 6 p4 = Instr(p3 + 1, Ucase(l), """") target = Mid(l, p3, p4 - p3) If Instr(Ucase(l), "ALT=""[DIR]""") > 0 Then 'recursive folder downloading downloadfolder(url & target, path & target) Else 'save a file If downloadfile(url & target, path & target) Then crash("Cannot download file " & path & target) End If End If Loop Until p1 > Len(index) End Sub Dim As String url, target url = getclipboard() If Ucase(Left(url, 4)) <> "HTTP" Or Instr(url, Chr(10)) > 0 Or Right(url, 1) <> "/" Then crash(url & " is not a valid URL!") Print "Downloading folder " & url Print "Enter the target folder:" Line Input target If Right(target, 1) <> "/" And Right(target, 1) <> "\" Then target += "/" downloadfolder(url, target) Print "Complete!" Sleep()