Proof of concept code for download of files from a D-link DIR-505 with USB stick using the Shareport service via HTTP. Probably works for similar models too, but might need adjustment of the USB path.
Tested against DIR-505 running firmware version 1.09.
DIR-505 authentication process
When authenticating (using a web browser), the DIR-505 shareport system will direct the user to make a GET request to the login URL with no parameters. This returns a JSON response with several parameters. The two parameters to look out for in this response are 'uid' and 'challenge'. The former will serve as an access key once authenticated, and the latter will be used to hash the password from the login form. The 'uid' value should be saved to a cookie for future use.
Now that the challenge has been completed, the username and hashed value are posted to the login URL. If successful, the cookie created earlier can now serve as an authentication token for future requests.
You can now make direct requests to the file API to discover files and directories on the connected USB stick. The same token can be used to download files from the USB stick.
Interface bug and limitations
The DIR-505 Shareport system seems to have a bug where read-only users cannot actually view any files on the interface. Because of this, the user used for this example must have read and write access on the Shareport system.
This is a fairly basic example, and does not download files recursively. Feel free to extend the code to support this.
Paths on device
|/dws/api/Login||Generates the challenge key for password hashing and handles the login process.|
|/dws/api/ListFile||Lists files on the connected USB device.|
|/usb_dev/usb_A1/||Root folder of the USB device for downloads once authenticated. Note that there are no directory indexes (use the ListFile API above). This path might be different for different devices.|