If you need to automatically download a file from a SFTP site, perhaps a regular news or traffic MP3, cURL may be the tool for you! These instructions explain the right versions of the software to download on Windows, and the correct commands to run.

Let’s assume you have a fairly recent Windows x64 version (Windows 7, Server 2008 R2, etc.)

There are two packages you need to download:

  1. cURL with SSH2, SSL and SSPI
  2. OpenSSL

These two tools can be used together to connect to SFTP sites and download specific files.

Step 1: Downloading cURL (with SSH2, SSL and SSPI) for Windows

cURL builds for Windows are distributed by paehl.com. On the downloads page, select the fourth version in the main list (“Download SSH2, SSL, SSPI version”).

CURL Download Screenshot

Step 2: Downloading OpenSSL for Windows

OpenSSL for Windows builds are distributed by fulgan.com. On the download page, select the latest i386-win32 version. At the time of writing, this file was called “openssl-1.0.2h-i386-win32.zip”.

OpenSSL Download Screenshot

Step 3: Extracting the files

We need to get two files from each ZIP archive and put them into the one directory.

From the cURL download, find:

  • curl.exe
  • libssh2.dll

From the OpenSSL package:

  • libeay32.dll
  • ssleay32.dll

Create an empty directory on your local disk, and copy these four files into it.

Step 4: Install Visual C++ Redistributable (Optional)

You may need to install the Visual C++ Redistributable. If so, this can be downloaded directly from Microsoft.

Step 5: Running the Command

The command itself is fairly straightforward. The following example assumes you want to download a file called “NEWS_FULL.mp3” and save it as “news_output_full.mp3”:

curl.exe -u myusername:mypassword -k -o c:filedownloadnews_output_full.mp3 sftp://myserver.mediarealm.com.au/home/myusername/NEWS_FULL.mp3

cURL Download SFTP Screenshot

Command Explanation

Here’s an explanation of the command line options:

  • -u myusername:mypassword
    Specify the credentials you need to login to the SFTP server. If the credentials contain special characters, wrap the whole thing in double-quotation marks.
  • -k
    This option is optional, but will allow you to connect to untrusted servers (self-signed certificates count as untrusted)
  • -o c:filedownloadnews_output_full.mp3
    Specify the full output filename
  • sftp://myserver.mediarealm.com.au/home/myusername/NEWS_FULL.mp3
    The last parameter is the source filename, with the full protocol, server, path and filename listed.

Automating this Command

To automatically run this command, save the full command as a BAT file and schedule it from the Windows Task Scheduler.