Solved

Downloading files from Internet in VB

Posted on 1998-12-29
12
239 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
Comment Utility
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
Comment Utility
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
Comment Utility
Oh, No! I was just late by 15 minutes from MikeP. anyway, hope you got the idea.

vmano
0
 

Author Comment

by:matco
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Accepted Solution

by:
vmano earned 70 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Bought This Question.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now