Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sdk:remote-configdownload [2017/11/16 15:19] (current)
juraschek created
Line 1: Line 1:
 +====== Download a Remote Config File and Delete it afterwards ======
 +
 +A very simple Method to roll out configfiles on a bunch of Router: ​
 +
 +The Router will try to download a config file from a ftp server with a unique part in the URL. 
 +After the File was downloaded successfully it will be deleted on the remote ftp server.
 +
 +This way you won't have a endless download. ​
 +
 +This Script can be used with various triggers: periodicly every XX min, after wan-up, sdk-startup and so on
 +
 +
 +<code c remote-config-download.are>​
 +/* DESC: The Router will try to download a config file from a ftp server with a unique part in the URL. 
 + * DESC: After the File was downloaded successfully it will be deleted on the remote ftp server
 + * Copyright (C) 2017 JJ NetModule AG, Switzerland
 + */
 + 
 +// ftp/​http/​ftps/​https is possible here
 +url="​ftp://​myfileserver.ch/";​
 +user="​ftpusername";​
 +pw="​ftppassword";​
 +
 +// Get Unique Part of the URL via Serial Number or Hostname
 +//​unique=nb_status("​info"​).SERIAL_NUMBER;​
 +unique=nb_config_get("​network.hostname"​);​
 +// File name on the server
 +image="​cfg.zip";​
 +
 +
 +// local file for storage
 +local="​configfile.zip";​
 +
 +
 +//We will have a remote update Link like: ftp://​myfileserver.ch/​myhostname/​cfg.zip
 +link=sprintf("​%s/​%s/​%s",​url,​unique,​image);​
 +
 +
 +DELAY=120;
 +TRIES=5;
 +for  (i=0;​i<​TRIES;​ i++) {
 + if (0 == nb_transfer_get(user,​pw,​link,​local)) {
 + nb_syslog("​Configfile Download successful, %s",​link);​
 + nb_transfer_delete(user,​pw,​link);​
 + nb_update_config(sprintf("​file:///​%s",​local));​
 + exit(0);
 + } else {
 + nb_syslog("​Configfile Download not successfull,​ retry"​);​
 + }
 +
 + sleep (DELAY);
 +
 +}
 +nb_syslog("​Could not download for %d seconds, abort config download",​DELAY*TRIES);​
 +
 +
 +</​code>​
 +
 +