C# - Automatic downloader with web API

Job ID: 33400102

Budget: $30 – $250 USD

C# Project:
- Needs to run as a windows service (Should automatically start if it exits for any reason)
- Automatically download files from a list of URLs and download paths in a json file (queue.json - Example below)
- There should be a config with a default download path (config.json)
- The downloads should be downloaded to the path in the "queue.json" and if a path is not defined then it should use the default path in the config.json
- Automatically write/append a log which is named as the current date (progress-DD-MM-YYYY.log)
- Log entries should contain download progress in Percentage, Download Speed, and total MB/GB downloaded
- Log should report when a download is complete and when a new one is started
- Log should report any failed downloads with a reason for the failure
- If a download fails then it should mark it as failed in the queue.json by adding "failed" key
- After a failure, it should retry downloading it
- Each time the download fails it should incrememnt the failed number in the queue.json
- If the download fails more than 3 times then it should not retry
- Once a download is complete, the file should be checked to make sure it downloaded entirely to prevent false positives

- Needs an API over a built in web server with following features:
-- API must respond with JSON response
-- Response must contain success or error (error must have a description with reason)
-- All API requests require a security hash which is calculated based on a secret string, a secret number and all GET data hashed with MD5, I will provide an example of how this is achieved in PHP.
-- /addlink endpoint - Adds a link into a file
--- Option to give directory of where the file should be downloaded to
-- /deletelink endpoint - Removes a link from the file
-- /movefile endpoint - Move a file from one path to another path
-- /deletefile endpoint - Delete a file from the system for the given path
-- /renamefile endpoint - Rename a file at the given path to the given name
-- /downloadfile endpoint - Delivers a downloads of the file from the given path to the browser
-- All endpoints should have a callback URL option to POST the result to another web server along with a hash generated using the same method as the checkHash function below (For example, when a download completes or fails, it should POST the result to a web server if a callback URL is provided to the API)

- Web server must have a JSON config with the following options:
-- Enable/Disable Web Server
-- Web Server Port
-- Enable/Disable SSL on Web Server
-- SSL Certificate must be in its own files (key.pem and cert.pem)
-- Secret String
-- Secret Number
-- Enable/Disable IP Whitelist (When Whitelist is disabled, anyone can use the web server API)
-- IP Whitelist (Array) - An empty array means no IPs are whitelisted therefore nobody can use the web server externally except localhost
-- IP Blacklist (Array) - This should always be enforced, even if the whitelist is disabled (An empty array would mean no IPs are blacklisted)

Example Download Links File:
[{"url":"https://abc123.com/somefile.mp4","path":"C:\\somepath","failed":0},{"url":"https://anothersite.com/anotherfile.mp3","path":"C:\\somepath123","failed":0},{"url":"https://somewhereelse.com/afile.exe","path":"C:\\Downloads","failed":3}]

PHP check hash function:

function escapeURL($s) {
$s=str_replace(
array(" ","+","-",".","_"),
array("%20","%20","%2D","%2E","%5F"),
urlencode($s));
return $s;
}

function checkHash($secstring,$secnum,$APIData) {
$hash=$_GET["hash"];
$body="";
$cpt=0;

foreach ($APIData as $name => $value) {
if ($name == "hash") continue;
if ($cpt++ > 0) $body .="&";
$body .= escapeURL($name)."=".escapeURL($value);
}

$calcHash=md5($body.$secstring.":".$secnum);
if ($hash!=$calcHash) return false;
return true;
}
Related categories: PHP C# Programming JSON