Solved

How can you programatically download a file and run it ?

Posted on 1998-09-01
9
192 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide vba in gp 7 125
I need help embedding an image as HTML in my vb.net application 3 84
Problem to line 23 79
Excel Web Add-in Where is Visual Basic used 9 71
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

738 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