Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Downloading files from Internet in VB

Posted on 1998-12-29
12
Medium Priority
?
254 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…
Suggested Courses

636 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