Solved

How can you programatically download a file and run it ?

Posted on 1998-09-01
9
189 Views
Last Modified: 2010-04-30
Hello,

I'm a fairly experienced VB 5 programmer that recently came across a need to download and run/install patches as part of the program I'm writing.  This will be part of an "Auto-Update" feature I'm creating.  I have access to HTTP and FTP server space that I can upload files to and then have downloaded from but I need to know how to go out and get the file, download it, then run it as part of my program.

I know that you can just use the Shell command to run the file once downloaded, but getting the file downloaded is the problem.

Please help,

HATCHET
0
Comment
Question by:HATCHET
  • 4
  • 3
  • 2
9 Comments
 
LVL 6

Accepted Solution

by:
clifABB earned 30 total points
ID: 1432328
If you're using VB5, you can use the Internet Transfer Control.
After you add this control to the project, place the control on a form (Form1 in this example):

To download:
  Form1.Inet1.RemoteHost = "ftp://www.duck.org
  Form1.Inet1.URL = "ftp://www.duck.org/
  Form1.Inet1.UserName = "LoginName"
  Form1.Inet1.Password = "password"
  Form1.Inet1.Protocol = icFTP
  Form1.Inet1.Execute "ftp://www.duck.org/", "GET TestFile.txt C:\TestFile.txt"

Of course replace the url, loginname and password with the appropriate info.
0
 
LVL 3

Author Comment

by:HATCHET
ID: 1432329
clifABB,

I tried your code and suggestion.  I have SP3 so the ActiveX control was there.  When i tried it, I didn't get any errors or anything, but there was no way to tell the progress of the download, or if it was infact downloading at all.  I could hear the hard drive making noises as if it was recieving a file, but I couldn't tell where it was receiving the file to.

Could you please help a bit more by adding to this a way to tell the following things :

1)  If the download has started
2)  The progress of the download if it does start
3)  Where the file is being downloaded from and to
4)  When the download has finished

Thank You,

HATCHET

P.S. - Of course, for additional help, I'd be glad to increase the points given for your efforts.

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1432330
The download begins when the execute line is called.  To tell when the download has finished, add the following code after the Execute line:
  While Form1.Inet1.StillExecuting
    DoEvents
  Wend
  MsgBox Form1.Inet1.ResponseInfo, vbOKOnly, "File Transfer"

Unfortunately, there is no way of telling the progress of the download.  However, you might look in the help file for StateChanged Event which will give you some information as to displaying what the current status is.

As far as where the file is being downloaded from, this is way beyond the scope of the question and, unfortunately, I don't have the time to create the code.  If you look in the help file under Execute method, you can see where you can get a directory listing of the remote drive.  With this data, you can then create a file list.  To where the file is being downloaded to, you can use the common dialog control.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 3

Author Comment

by:HATCHET
ID: 1432331
clifABB,

Thank you for your time.  You've definately set me on the right path and I can now do what I need to do with this.  =]

With the combined help files and the help you've given me, I could probibly make my own FTP client, but need the code for something much simpiler.

Take care,

HATCHET
0
 

Expert Comment

by:stat
ID: 1432332
Dear clifABB,
I wrote your command(like your's) and program was run, but:

Inet1.ResponseInfo sent 3 command
1: 200 Type set I.
2: 200 Port command successful
3: Testfile.txt:No such file or directory.
I'm using cuteftp and I loged anonymous and the file was here.

Thanks,
stat
0
 

Expert Comment

by:stat
ID: 1432333
Dear clifABB,

I wrote your command(like yours) and the prog. was run but
Inet1.ResponseInfo sent 3 commands.
1: 200: Type set to I.
2: 200: Port command successful
3: 550: testfile.txt:No such file or ditectory
I am using cuteftp, I loged anonymous the file was here.

Thanks,
stat
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1432334
Sorry, I forgot that UNIX is case sensitive.  Make sure you use lower case for the filename (testfile.txt) in my above example.
0
 

Expert Comment

by:stat
ID: 1432335
Dear clifABB,
I am sorry but Can I ask one question.
If my file ist't in root, How can I download it.
(sample ftp.medkar.com.tr/miro/remote.zip)
I tried some method but I didn't succesfull.
The file is here.(8923 byte)
The site accept anonymous login. Please help me.
Thanks,
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1432336
I used the following code and DL'd the zip file (remote.zip).
The path you are to be downloading from (and to) will be specified in the 'GET' phrase of the Execute method.

  Form1.Inet1.RemoteHost = "ftp://ftp.medkar.com.tr"
  Form1.Inet1.URL = "ftp://ftp.medkar.com.tr/"
  Form1.Inet1.UserName = "anonymous"
  Form1.Inet1.Password = "clif@duck.org"
  Form1.Inet1.Protocol = icFTP
  Form1.Inet1.Execute "ftp://ftp.medkar.com.tr/", "GET /miro/remote.zip C:\remote.zip"

  While Form1.Inet1.StillExecuting
    DoEvents
  Wend

I hope this helps.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…

856 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