Author Topic: How to download file  (Read 2055 times)

0 Members and 1 Guest are viewing this topic.

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
How to download file
« on: November 23, 2021, 11:55:02 am »
Hi,
I have marketed a warehouse management program made in QB64 and currently 14 companies have it. As each company has an average of 3 computers, the program is installed on 42 computers.
Every time I update the program for an improvement or correction of an error, I have to do it on all 42 computers one by one.
Is there a way to make when it enters the program, it will check for an update in a folder on my NAS and download it directly?
Thanks

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
Re: How to download file
« Reply #1 on: November 24, 2021, 09:52:32 am »
Isn't it possible to do it?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
Re: How to download file
« Reply #2 on: November 24, 2021, 10:26:53 am »
It sounds interesting. I would divide it into several steps.
So first of all. Try writing a simple program with _OPENHOST and _OPENCLIENT and use the _FILEEXISTS function to see a specific file on the NAS. If this works, you can go to step 2.

Step 2 will be - write a program that will start again after its completion (the update will take place at startup, right?)

Here I wrote a quick look at how I would try to do it, I didn't even run the program. If you get on the NAS and if windows allows you to rename EXE files, you have win.

Code: QB64: [Select]
  1.  
  2.  
  3. If _FileExists("//NAS/autoupdate.cfg") Then 'this file is on server NAS
  4.     ff = FreeFile
  5.     Open "//NAS/autoupdate.cfg" For Input As ff
  6.     Input #ff, version
  7.     Close ff
  8.  
  9. Print "NAS version available is: "; version
  10.  
  11. Open "localversion.cfg" For Input As ff
  12. Input ff, myversion
  13.  
  14. Print "My version is: "; myversion
  15.  
  16. If myversion < version Then
  17.  
  18.     Open "Auto_update.bat" For Output As ff
  19.     Print #ff, "@ECHO OFF"
  20.     Print #ff, "TIMEOUT /T 3"
  21.     Print #ff, "del oldversion.exe"
  22.     Print #ff, "ren newversion.exe oldversion.exe" 'this maybe must be allowed in windows firewall
  23.     Close ff
  24.  
  25.     'download newversion.exe from NAS here
  26.  
  27.     'open newversion.exe on NAS
  28.     Open "//NAS/newversion.exe" For Binary As ff
  29.     FileLenght$ = Space$(LOF(ff))
  30.     Get ff, , FileLenght$
  31.     Close ff
  32.  
  33.     'create new file in local computer
  34.     Open "newversion.exe" For Binary As ff
  35.     Put ff, , FileLenght$
  36.     Close ff
  37.  
  38.     'write new version number to config file
  39.     Open "localversion.cfg" For Output As ff
  40.     Print ff, version
  41.     Close ff
  42.  
  43.     'restart program and start new version
  44.     Shell _DontWait "Auto_update.bat"
  45.     System
  46.  
  47.  
« Last Edit: November 24, 2021, 10:48:01 am by Petr »

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
Re: How to download file
« Reply #3 on: November 24, 2021, 12:15:42 pm »

Thank you very much Petr.
I find the program that you attach very interesting.
What I really wouldn't know how to do is connect from an external computer and download the program.

FellippeHeitor

  • Guest
Re: How to download file
« Reply #4 on: November 24, 2021, 12:40:53 pm »
There's a simple download routine in our wiki at http://www.qb64.org/wiki/Downloading_Files

Notice it won't work over secure https connection though, but it can still be useful. It's the same base code we use in the IDE to download wiki pages and update information, as well as the same code InForm uses for its installer/autoupdater, so you know it works.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • GitHub
Re: How to download file
« Reply #5 on: November 24, 2021, 12:49:14 pm »
I do have code for downloading HTTPS files and for FTP but it's been a while. Are you on Windows? If so, then it could be useful. Otherwise, no.
Shuwatch!

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
Re: How to download file
« Reply #6 on: November 24, 2021, 12:53:38 pm »
There's a simple download routine in our wiki at http://www.qb64.org/wiki/Downloading_Files

Notice it won't work over secure https connection though, but it can still be useful. It's the same base code we use in the IDE to download wiki pages and update information, as well as the same code InForm uses for its installer/autoupdater, so you know it works.
Thanks FellipeHeitor,
I will try everything you have told me

I do have code for downloading HTTPS files and for FTP but it's been a while. Are you on Windows? If so, then it could be useful. Otherwise, no.

Yes, I use Windows.
I would appreciate if you could pass me the code. See if I can do it.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • GitHub
Re: How to download file
« Reply #7 on: November 24, 2021, 12:59:39 pm »
My FTP code is out of date but I can't get the current one now since my PC is out of commission. Here is the code I uploaded last year:
https://www.qb64.org/forum/index.php?topic=3263.msg125410#msg125410

For HTTP/HTTPS downloading, more updated (March of 2021):
https://www.qb64.org/forum/index.php?topic=3729.msg130859#msg130859
Shuwatch!

Offline Juanjogomez

  • Forum Regular
  • Posts: 117
Re: How to download file
« Reply #8 on: November 24, 2021, 01:10:51 pm »
Thanks, i will try this.
This forum is wonderful and QB64 too