Solved

How can you programatically download a file and run it ?

Posted on 1998-09-01
9
188 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

770 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