Differences

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

Link to this comparison view

sdk:download-to-usb [2015/09/04 14:27] (current)
juraschek created
Line 1: Line 1:
 +====== Download a File and Store it to a USB Flash Drive ======
  
 +If you need to download a File and store it to a USB flash drive attached to a router you can use the script below.
 +
 +You need to configure the download URL and the local File name at the beginning of the script
 +
 +<code c>
 +## URL where to download from
 +DOWNLOADURL="​http://​www.mywebserver.com/​niceFile.bin";​
 +## URL where to save the file to (without USB Media Folder)
 +LOCALFILE="​downloaded-file.bin";​
 +
 +</​code>​
 +
 +
 +
 +<code c download-to-usb.are>​
 +
 +
 +## URL where to download from
 +DOWNLOADURL="​http://​www.mywebserver.com/​niceFile.bin";​
 +## URL where to save the file to (without USB Media Folder)
 +LOCALFILE="​downloaded-file.bin";​
 +
 +
 +## FTP/HTTP Credentials
 +USR="";​
 +PWD="";​
 +
 +USBDEV="​usb0";​
 +USBDIR="/​mnt/​media/​usb0/";​
 +
 +ret = nb_media_mount(USBDEV);​
 +if (ret == 0) {
 +    nb_syslog("​Successfully mounted usb0\n"​);​
 +}
 +else {
 +  nb_syslog("​Unable to mount usb0 (rc %d)\n",​ ret);
 +}
 +
 +
 +mounted = nb_media_getmount();​
 +nb_syslog(sprintf("​Mounted media:",​mounted));​
 +
 +
 +
 +if (nb_transfer_get(USR,​ PWD, DOWNLOADURL,​ sprintf("​%s/​%s",​USBDIR,​LOCALFILE)) == -1) {
 +    nb_syslog("​could not download %s", DOWNLOADURL);​
 +} else { 
 +nb_syslog(sprintf("​downloaded:​ %s to %s on usb drive",​DOWNLOADURL,​LOCALFILE));​
 +}
 +
 +nb_media_umount(USBDEV);​
 +
 +
 +
 +
 +
 +</​code>​