?
Solved

Downloading files from Internet in VB

Posted on 1998-12-29
12
Medium Priority
?
258 Views
Last Modified: 2008-02-01
I am working on a utility which will need to download an INI file from the net, then read it and download the files it has listed in the INI file.

Basically, I need to know how to tell VB to download a file from a certain URL and also how to put it in a certain folder.

I can get my program to read the INI file from the NET but I don't know how to download a file, like and EXE or BMP from the NET.

Thanks,
-Matt
0
Comment
Question by:matco
12 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1453063
You can use the Internet Transfer Control (VB5-6*) for that. It includes a sample (in the help), which does exactly that, both for HTTP and FTP. If you need any more help, just ask.


0
 
LVL 3

Expert Comment

by:vmano
ID: 1453064
1.Using the OpenURL Method of INet control to Retrieve an HTML Page

'objInet is your Inet control on the form.
Private Sub cmdWriteFile_Click()
   Dim b() as Byte
 
  ' Set the internet transfer control protocol and URL.
   objInet.Protocol = icHTTP
   objInet.URL = "HTTP://www.microsoft.com"
 
   ' Retrieve the HTML data into a byte array.
   b() = objInet.OpenURL(objInet.URL,icByteArray)
 
   ' Create a local file from the retrieved data.
   Open "C:\Homepage.htm" For Binary Access Write As #1
   Put #1, , b()
   Close #1
 
   MsgBox "Done"
End Sub

(2)Using FTP to Retrieve a File from an FTP Site
'objFTP is your INet control
Private Sub cmdGetFile_Click()
  Dim strSite As String
  Dim strFile As String

  strSite = Me!txtFTPSite
  strFile = Me!txtFileName
 
  objFTP.Protocol = icFTP
  objFTP.URL = strSite
  objFTP.Execute strSite, "Get " & strFile & " C:\" & strFile
End Sub

let me know if this helps
vmano
0
 
LVL 3

Expert Comment

by:vmano
ID: 1453065
Oh, No! I was just late by 15 minutes from MikeP. anyway, hope you got the idea.

vmano
0
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!

 

Author Comment

by:matco
ID: 1453066
Okay, MikeP's answer is probably good but I don't have the help...help is on MSDN CD-ROM and I am using this at work and have no CD-ROM:( Long Story.

Anyhow...Vmano had the right answer....so how do I give him credit?

Also, is there a way to use this inet control on a password protected site? I have a FP98 password protected site where I want to get these files from. I was screwing around with the password and username properties but it doesn't seem to work? Any ideas?


0
 
LVL 3

Expert Comment

by:vmano
ID: 1453067
I think this is what you are looking for. this code is for logging on to the FTP servers.(this code and text is taken straight from the help file)

With Inet1
   .URL = "ftp://ftp.someFTPSite.com"
   .UserName = "John Smith"
   .Password = "mAuI&9$6"
   .Execute ,"DIR"   ' Returns the directory.
   .Execute ,"CLOSE" ' Close the connection.
End With

After you have invoked the Execute method, the FTP connection will remain open. You can then continue to use the Execute method to perform other FTP operations such as CD and GET. When you have completed the session, close the connection using the Execute method with the CLOSE operation. You can also close the connection automatically by changing the URL property, and invoking either the OpenURL or Execute method; such action will close the current FTP connection, and open the new URL.

let me know if this is what you are looking for,
vmano
0
 

Author Comment

by:matco
ID: 1453068
Well, this kind of sucks....I just realized what I did wrong and guess what. It doesn't even need an ID and pass, it will download files without them.....but if you go there with IE it will require a password. The site is on a Front Page 98 server...any idea why the Inet control in VB doesn't get prompted for a password?

Anyhow, how do I give you (vmano) credit for answering my question...I am new to this site and don't know how, and don't want you to get screwed out of your points.
0
 
LVL 3

Accepted Solution

by:
vmano earned 280 total points
ID: 1453069
OK. I am posting my previous comment as answer.

1.Using the OpenURL Method of INet control to Retrieve an HTML Page

'objInet is your Inet control on the form.
Private Sub cmdWriteFile_Click()
   Dim b() as Byte
 
  ' Set the internet transfer control protocol and URL.
   objInet.Protocol = icHTTP
   objInet.URL = "HTTP://www.microsoft.com
   
   ' Retrieve the HTML data into a byte array.
   b() = objInet.OpenURL(objInet.URL,icByteArray)
 
   ' Create a local file from the retrieved data.
   Open "C:\Homepage.htm" For Binary Access Write As #1
   Put #1, , b()
   Close #1
 
   MsgBox "Done"
End Sub

(2)Using FTP to Retrieve a File from an FTP Site
'objFTP is your INet control
Private Sub cmdGetFile_Click()
  Dim strSite As String
  Dim strFile As String

  strSite = Me!txtFTPSite
  strFile = Me!txtFileName
 
  objFTP.Protocol = icFTP
  objFTP.URL = strSite
  objFTP.Execute strSite, "Get " & strFile & " C:\" & strFile
End Sub

Thanks,
vmano
0
 

Author Comment

by:matco
ID: 1453070
So, anyone know why an FP98 site that is password protected (and works with password under IE) will allow the Inet VB control to go right in without a password?
0
 

Author Comment

by:matco
ID: 1453071
So, anyone know why an FP98 site that is password protected (and works with password under IE) will allow the Inet VB control to go right in without a password?
0
 

Author Comment

by:matco
ID: 1453072
So, anyone know why an FP98 site that is password protected (and works with password under IE) will allow the Inet VB control to go right in without a password?
0
 

Author Comment

by:matco
ID: 1453073
So, anyone know why an FP98 site that is password protected (and works with password under IE) will allow the Inet VB control to go right in without a password?
0
 
LVL 14

Expert Comment

by:waty
ID: 2210473
Bought This Question.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

840 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