Unleashing the Power of Curl: Simplifying SFTP File Transfers

You may have used tools like scp, rsync, sftp, and lftp to transfer files over SFTP. However, you can also accomplish this with curl. Using curl has its advantages, as you won't need to implement expect-scripts to handle password prompts or manual FTP get/put commands.

Here's an example snippet that downloads a file from a secure SFTP server using custom authentication.

SFTP_HOST=sftp://172.18.1.100
SFTP_AUTH=user:12345678
SFTP_FILE=/data/files/$(date --date="1 day ago" +%Y%m%d)

curl -v -u $SFTP_AUTH $SFTP_HOST/$SFTP_FILE -o $SFTP_FILE 2>&1