Results 1 to 13 of 13

Thread: File Downloader

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    23

    File Downloader

    Can anyone help me make a File Downloader?

    What I'm trying to make is actually simple to most of the decent coders but I don't have enough experience to do this....

    So what I want to make is a program that download all the files in a folder on a server.
    But it has to check to see if it's going to download or not
    and to check, what it does it compare 2 files
    1) on the program side ( where the program is at )
    2) on the server side

    so it will read the 2 file
    and if the 2 files are different then it will download all the files in a folder on the server and it will also download the file that it compared to with the one on the Program side.

    Note* I do not want to download the folder, I want to download what's in the folder, every files inside the folder

    And I would like to use a progress bar to show the progress of the download.

    I also wanted to make a config file that customize the program

    The config file can change the program like
    background image
    background color
    title
    size
    text ( like labels and button names )
    and etc
    _____________________________________

    Thanks alot if you can help
    Last edited by PingPong; Apr 21st, 2009 at 09:34 PM.

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    23

    Re: File Downloader

    Bump

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File Downloader

    that download all the files in a folder on a server
    do you have the list of files or you just want to llop through all the files?

    if you have a list of files you can easily use urldownload2file API
    but if you need to loop through the files you would need FTP access and use ftp API or inet control to get the file list, i don't believe you can loop through files on most web servers

    though you do not specify if it is a local server or internet server, so maybe i am making wrong assumptions
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    23

    Re: File Downloader

    Im going to host the files on my computer
    so the server would be my computer

    the files will change from time to time
    ( like different files will be put into the Updates folder.

    So I have to use an ftp for it to look through the folder?

    and how do I make the config file to edit the program?

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File Downloader

    use an ini file, or just a basic textfile to save the settings you want to use
    read the file in form load event and apply the saved settings

    Im going to host the files on my computer
    so the server would be my computer
    are the people downloading doing on lan or internet?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    23

    Re: File Downloader

    I got the config file down now

    Now all I need to do is get the code to check if the ver number are the same or not.
    ( I can do this part, it's a lame way to do it but atleast it works )

    Now what I need to do is get it to download ( using a button ) if the version number are different.

    I want it to download all the Items in a specific folder. ( download items in it, Not The Folder )

    And i want a progress bar to show the status....

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File Downloader

    if your know the names of all the files in the directory, or you can list the files in the first file, the one you use to compare, you can loop through the list, without looping through the files in the folder, if that is the case the simplest method is to use urldownload2file API

    example, comparison file
    2.01
    textfile.text
    configfile.cfg
    somefile.exe
    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
    
    Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" _
       Alias "DeleteUrlCacheEntryA" _
      (ByVal lpszUrlName As String) As Long
    Code:
    Private Function DownloadFile(ByVal sURL As String, _
                                 ByVal sLocalFile As String) As Boolean
        Call DeleteUrlCacheEntry(sUrl)
       DownloadFile = URLDownloadToFile(0, sURL, sLocalFile, 0, 0) = ERROR_SUCCESS
       
    End Function
    vb Code:
    1. Dim myurl As String, fname As String, sSourceUrl As String, slocalfile As String
    2. Dim f As Integer, dlfail As Boolean, flist() As String
    3. myurl = "http://someurl.com/"
    4. fname = "verfile.txt"
    5. sSourceUrl = myurl & slocalfile
    6. slocalfile = app.Path & "\" & fname
    7.    If downloadfile(sSourceUrl, slocalfile) Then
    8.     f = FreeFile
    9.        Open slocalfile For Input As f
    10.        flist = Split(Input(LOF(f), #f), vbNewLine)
    11.        Close f
    12.        ' compare first line of file to some version number
    13.        If flist(0) = app.major Then MsgBox "no need to upgrade": Exit Sub
    14.        ' download all files in list in file
    15.        ' if the last or any other line is empty will cause error
    16.        For i = 1 To UBound(flist)
    17.         If Not downloadfile(myurl & flist(i), app.Path & "\" & flist(i)) Then dlfail = True
    18.        Next
    19.        If dlfail Then MsgBox "some file failed to download correctly"
    20.   End If
    this is untested, you can use any variable to compare to ver# in file, needs some error handling, possibly list which file /s failed to download, if it vista do not use app.path

    you can search on progress bar, there is many examples in the forum, if the files are of similar size just work it out on the number of files
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    23

    Re: File Downloader

    I can check the file version now
    All I need is a simple code that downloads every item in a specific folder

    this is how I check the Version file

    Have 2 Version.xml File on each side ( Host and Program )
    When they click the button to check for updates, the button will make a richtextbox in form2 = to the Version.xml
    Then it will read the server's xml file and make RichTextBox2 = to the server
    and if those 2 = to each other then no download will be made

    if it doesn't = to each other ( this is where Im stuck at ) then it download everything in a specific folder.

  9. #9
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: File Downloader

    If you have users using you app you may want to change how it works.
    Have your online xml version compare to App.Minor or major. if you make a new version just change the online xml version. No need for a second client xml.
    You can use
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    23

    Re: File Downloader

    Quote Originally Posted by isnoend07 View Post
    If you have users using you app you may want to change how it works.
    Have your online xml version compare to App.Minor or major. if you make a new version just change the online xml version. No need for a second client xml.
    You can use
    What?

    I have the program compare the 2 files and it checks to see wether they are the same or not.

    1 from program side and 1 from server

    all I need now is to download and have a progressbar show the status

  11. #11
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: File Downloader

    Quote Originally Posted by PingPong View Post
    What?

    I have the program compare the 2 files and it checks to see wether they are the same or not.

    1 from program side and 1 from server

    all I need now is to download and have a progressbar show the status
    have you tried the code posted by westconn1 ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    23

    Re: File Downloader

    I don't know where to put those

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File Downloader

    I don't know where to put those
    in a button click event or whatever other you want to start the progress
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width