copy http flash – download from HTTP server to the Cisco router


You may need to download a remote file (usually IOS image, but anything goes) to the Cisco router via HTTP.  The command is simple, but be aware of few caveats:
Router# copy http[:full URI specification]  flash[: local path to save the file]

The caveats you should know:

- router first resolves the server's domain name to the IP, then uses this IP as the Host header in the  communication with the remote HTTP server. This is important when you try to download something from the webserver already configured for the Virtual hosts. Because then webserver looks at this header and searches for the matching local file according to its internal logic.
For example if using Apache configured for named Virtual hosting you should put the file to be downloaded in the default Virtual host, i.e. first virtual host in the Apache configuration file. Let’s look at the example.
Here we have  the partial Apache config file :

    #The file we want to download is in /usr/local/apache2/htdocs/mrtg/test.bin

    #Here comes the 1st VirtualHost entry
    <VirtualHost *:80>
       ServerAdmin  [admin@yurisk.net](mailto:admin@yurisk.net)
       DocumentRoot "/usr/local/apache2/htdocs/mrtg"
    # as this this the 1st Virtual Host entry server names below are irrelevant for our case
       ServerName mrtg.yurisk.info
       ServerAlias mrtg. yurisk.net
       ErrorLog "logs/mrtg.yurisk.info-error_log"
       CustomLog "logs/mrtg.yurisk.info-custom_log" common
    <Directory />
       Options FollowSymLinks
       AllowOverride None
    #Here I set up a basic authentication with local user/pass file, you may omit this
           AuthType  Basic
           AuthName  "By My Invitation only :)"
           AuthUserFile /usr/local/apache2/passwords
           Require valid-user
           Options None
    #Uncomment below if not using the authentication
    #    Order allow,deny
    #    Allow from any

    </Directory>

    <VirtualHost *:80>

- it is always a good idea to verify the downloaded file with md5 sum. The command:

    #verify /md5 flash:<downloaded file name>

- This command also supports copying from HTTPs, but it would add unwanted SSL encrypt/decrypt overload so I haven’t tested it , yet.

Now the real life example:

      Tair#copy [http://qwerty:12345](http://qwerty:12345/)@ 214.90.51.41/test.bin flash
    Destination filename [test.bin]?
    Loading http:// qwerty:12345@ 214.90.51.41/test.bin
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    5120000 bytes copied in 17.924 secs (285651 bytes/sec)
    Tair # verify /md5 flash:test.bin
    ...........................................................................................................................................................................................

    .............................................................................................................................................................................................

    ..........................................................................................................................Done!
    verify /md5 (flash:test.bin) = e8c39d44aafc82b035dfc7ad16fc2183

Follow me on https://www.linkedin.com/in/yurislobodyanyuk/ not to miss what I publish on Linkedin, Github, blog, and more.