Link to home
Start Free TrialLog in
Avatar of matco
matco

asked on

Downloading files from Internet in VB

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
Avatar of MikeP090797
MikeP090797

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.


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
Oh, No! I was just late by 15 minutes from MikeP. anyway, hope you got the idea.

vmano
Avatar of matco

ASKER

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?


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
Avatar of matco

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of vmano
vmano

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of matco

ASKER

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?
Avatar of matco

ASKER

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?
Avatar of matco

ASKER

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?
Avatar of matco

ASKER

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?
Bought This Question.