Solved

How can you programatically download a file and run it ?

Posted on 1998-09-01
9
186 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now