Solved

Downloading files from Internet in VB

Posted on 1998-12-29
12
249 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
[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
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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 70 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

Technology Partners: 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

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 …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 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