Solved

Download a text file using HTTP

Posted on 2000-03-16
9
184 Views
Last Modified: 2012-05-04
Can anyone give me an EXAMPLE of how to download a text file from a server onto the local machine without any user interaction (ie no prompts to run from current location or save).

Ie the answer I am looking for is a complete version of the following

Public Function GetFile(byval sURL as string, byval sFileName as string) as Boolean

    'Download and store file at sURL as sFilename
    'Return True/False based on success of operation

End Function


I have seen a very similar question posted here before but the accepted answer wasnt a complete solution and I cant get it to work.

Anybody able to provide me with a complete example in the format above ?

Cheers
0
Comment
Question by:paulstamp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2622736
are you partial against using the inet control?
0
 
LVL 3

Author Comment

by:paulstamp
ID: 2622740
Nope... thats fine.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2622749
well you can stick an inet control on your form and try this:

Dim b() As Byte
Dim intCount As Integer
Dim strData As String

Inet1.Cancel ' Stops any current operations

b() = Inet1.OpenURL("http://www.vbsquare.com/index.html", icByteArray)

For intCount = 0 To UBound(b) - 1

  strData = strData & Chr(b(intCount))
Next intCount

Open "myfile.txt" For Binary Access Write As #1

Put #1, , b()

Close #1



0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 28

Accepted Solution

by:
AzraSound earned 75 total points
ID: 2622765
If you wanted to write directly to the file on the disk and surpass first putting the info into a byte array then you can use:

Dim strURL As String      ' URL string
Dim intFile As Integer   ' FreeFile variable
IntFile = FreeFile()
strURL = "http://www.youresite.com/text.text"
Open "c:\temp\myfile.txt" For Output _
As #IntFile
Write #IntFile, Inet1.OpenURL(strURL)
Close #IntFile
0
 
LVL 28

Expert Comment

by:Ark
ID: 2622782
Hi
What do you meen "Text File?" Page?
Add Internet Transfer Control(Inet1) at your form

Private Function GetPage(sURL As String, sFile As String) As Boolean
   Dim nFile As Integer
   GetPage = True
   On Error GoTo ERROR_GetPage
   Dim b() As Byte
   Inet1.Cancel
   Inet1.Protocol = icHTTP
   Inet1.URL = sURL
   b() = Inet1.OpenURL(, icByteArray)
   nFile = FreeFile
   Open sFile For Binary Access Write As nFile
   Put nFile, , b()
   Close nFile

EXIT_GetPage:
   Exit Function

ERROR_GetPage:
Select Case MsgBox("Error " & Err.Number & ": " & Err.Description & " at line: " & Erl, vbAbortRetryIgnore + vbCritical, "Error")
       Case vbAbort
            Screen.MousePointer = vbDefault
            GetPage = False
            Resume EXIT_GetPage:
       Case vbRetry
            Resume
       Case vbIgnore
            GetPage = False
            Resume Next
End Select
Resume EXIT_GetPage
End Function
0
 
LVL 28

Expert Comment

by:Ark
ID: 2622792
Hi
AzraSound:Sorry, look at time when i posted message - I didn't see your comments.
Cheers
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2622797
Not a problem....the more the merrier for those who need answers  =)
0
 
LVL 3

Author Comment

by:paulstamp
ID: 2623015
Thanks AzraSound... thats pretty much what I needed. Only two minor problems :

a) Unfortunately it puts quotes around the data in the file but thats not a big issue.

b) It seems to be cacheing the file somewhere : The situation is I'm writing a vb front end to a web-based system (I'm writing both sides of the equation), and when I modify the text file on my web site I still seem to be getting the file I first downloaded.

Any ideas (not to worry if you havent - you have already answered my real question).

Cheers
0
 
LVL 3

Author Comment

by:paulstamp
ID: 2623060
Actually.. scrub the last point - I've found out why its downloading an old version - got two different versions of the web site and I'm looking at wrong one !
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
message box in access 4 55
vbModal 12 75
Set email body to html using vbscript 6 97
pop out of webbrowser1 control vba6 5 52
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question