Solved

How can you programatically download a file and run it ?

Posted on 1998-09-01
9
193 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
[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
  • 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
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!

 
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

SharePoint Admin?

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

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

724 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