Can VB6 download an entire folder/directory from my website, and save it to the app?
Hi again folks! I have another question about a program I am working on to help my students do their math work at home. I have a website that I put work on, but would like to have it so the program will download a directory folder from my website that has their work in it, and save it in the same folder as the app, but has the same folder name as the folder that was downloaded. For example, if the folder address on the internet was www.123.com/April4, then the folder downloads the April 4th folder, and keeps it the same name.
Has anyone here ever do anything like that? :)
Thanks!
Re: Can VB6 download an entire folder/directory from my website, and save it to the a
Why not upload an "April4.zip" to your WebServer (instead of an April4-Folder).
This would simplify:
- the download-operation (a single file)
- and the clientside "Folder-restore" as well.
Olaf
Re: Can VB6 download an entire folder/directory from my website, and save it to the a
you could make the "client" program download a file, maybe "april4.hwk", that is actually a simple text file with all the files you want the student to have.
the API:
Code:
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
is very easy to use and will do all the "downloading" and "creating files/folders" for you.
so: download april.hwk
parse the file, each line has:
https://www.123.com/April4/Instructions.pdf
https://www.123.com/April4/Tutorial.def
https://www.123.com/April4/Test/Test1.doc
well, you get it.
of course you need to do some "string" commands, to copy April4/Instructions.pdf and change / to \ etc and you need to know the "root/parent" folder of the home-folder.
Re: Can VB6 download an entire folder/directory from my website, and save it to the a
Thank you, so I went on this page and found the code to use URLDownloadToFile
VB Code:
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
Private Sub Form_Load()
Command1.Caption = "Download File"
End Sub
Private Sub Command1_Click()
Dim sSourceUrl As String
Dim sLocalFile As String
Dim hfile As Long
sSourceUrl = "http://vbnet.mvps.org/code/faq/fileloadtext.htm"
sLocalFile = "c:\deleteme.htm"
Label1.Caption = sSourceUrl
Label2.Caption = sLocalFile
If DownloadFile(sSourceUrl, sLocalFile) Then
hfile = FreeFile
Open sLocalFile For Input As #hfile
Text1.Text = Input$(LOF(hfile), hfile)
Close #hfile
End If
End Sub
Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean
'Download the file. BINDF_GETNEWESTVERSION forces
'the API to download from the specified source.
'Passing 0& as dwReserved causes the locally-cached
'copy to be downloaded, if available. If the API
'returns ERROR_SUCCESS (0), DownloadFile returns True.
DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS
End Function
IS there a way to check to see if the file has already been downloaded, and if so, don't download it 2x? :)
Thanks!
Re: Can VB6 download an entire folder/directory from my website, and save it to the a
Another small issue I have with the above code is that I'm try to test it out with a single pdf file.
When I use the code, it downloads the pdf file, but it gives me a debug error "input past end of file". What does that mean?
It highlights the line of code Text1.Text = Input$(LOF(hfile), hfile)
If DownloadFile(sSourceUrl, sLocalFile) Then
hfile = FreeFile
Open sLocalFile For Input As #hfile
Text1.Text = Input$(LOF(hfile), hfile)
Close #hfile
End If
Thanks!
Re: Can VB6 download an entire folder/directory from my website, and save it to the a
It means you tried to read a record but there was no record to read. This occurs when you try to read a record on an empty file (ie. the file has no records) or you have already read all the records and then you try to read another. If you want to avoid the error message just put On Error Resume Next before the Text1.Text = Input$(LOF(hfile), hfile) line and then after that line put an If Err Then....Else....End If clause. I think another way is to check the LOF before you attempt to read (after the Open and before the Input lines): If LOF(hfile) = 0 Then.....
Re: Can VB6 download an entire folder/directory from my website, and save it to the a
Quote:
Originally Posted by
Ordinary Guy
It means you tried to read a record but there was no record to read. This occurs when you try to read a record on an empty file (ie. the file has no records) or you have already read all the records and then you try to read another. If you want to avoid the error message just put On Error Resume Next before the Text1.Text = Input$(LOF(hfile), hfile) line and then after that line put an If Err Then....Else....End If clause. I think another way is to check the LOF before you attempt to read (after the Open and before the Input lines): If LOF(hfile) = 0 Then.....
Thanks, so I added the line, so my code looks like this now...
VB Code:
Dim sSourceUrl As String
Dim sLocalFile As String
Dim hfile As Long
sSourceUrl = "http://microhardxce.com/WeeklyNewsletters/WeeklyNewsletter-" & Desk.lblDate.Caption & ".pdf"
sLocalFile = App.Path & "\ResourceFiles\WorkActivities\WeeklyNewslettes\WeeklyNewsletter-" & Desk.lblDate.Caption & ".pdf"
Label1.Caption = sSourceUrl
Label2.Caption = sLocalFile
If DownloadFile(sSourceUrl, sLocalFile) Then
hfile = FreeFile
Open sLocalFile For Input As #hfile
On Error Resume Next
Text1.Text = Input$(LOF(hfile), hfile)
If Err Then
Else
End If
Close #hfile
End If
That fixed the problem. Thank you very much!
Re: Can VB6 download an entire folder/directory from my website, and save it to the a
Your If Err is not necessary if you are not going to use the Then...Else parts.
Code:
'
'
On Error Resume Next
Text1.Text = Input$(LOF(hfile), hfile)
If Err Then
'
' Do something if there is an error
'
Else
'
' Do something if no error
'
End If
'
'
Re: Can VB6 download an entire folder/directory from my website, and save it to the a
Hi again! I am experimenting with downloading a textfile that includes a list of all of the files to be downloaded for the day's school work.
Once downloaded, the file is loaded into a listbox.
I used this code to do it.
VB Code:
Public Sub LoadTheWorkList()
'This code will load the WorkToDo.txt to the listbox so the program can download all of the files needed for the day.
Dim ff As Long
Dim line As String
ff = FreeFile
Open App.Path & "\ResourceFiles\WorkActivities" & Desk.lblDate.Caption & "\WorkToDo.txt" For Input As #ff
Do While Not EOF(ff)
Line Input #ff, line
'make sure we're not adding a blank line
If Len(line) Then DownloadList.AddItem line
Loop
Close #ff
End Sub
What I would like to do, is loop through each item in that list and download it, but I am wondering where in the code would I add that? :) Thanks!
Re: Can VB6 download an entire folder/directory from my website, and save it to the a
I ran into that input past end error a while back on a text file. Turned out that the text file was in unicode format and that caused the error. The same file in ASCII format worked fine. Many native basic functions do not play well with unicode formatted files.