Using curl with vsftpd FTPS (FTP Over SSL)

Using curl with vsftpd FTPS (FTP Over SSL)

Using curl with vsftpd FTPS (FTP Over SSL)

I have to say there is NOT a lot of good documentation out there on the Internet, I had to completely build this procedure using MAN. It seems like nobody else on the planet has ever attempted this. Anyways, finally after 2 weeks we have a solution for to connect VSFTPD configured with FTPS or FTP over SSL Explicit using CURL.

Here’s what we were able to put together:

Basic Usage via UNIX/Linux:

List Files:
curl –ftp-ssl –insecure –user “username:password” ftp://ftp.server.com:991

you may want to use the -l option if you don’t want file details, just filenames

Upload File:
curl –ftp-ssl –insecure –user “username:password” -T test.txt ftp://ftp.server.com:991
 

Download File:
curl -o filename –ftp-ssl –insecure –user “username:password” ftp://ftp.server.com:991

Script to Download or get ALL Files in a Directory:

#!/bin/sh
# Created by Zwiegnet Linux Admins 1/31/2015
# Version 7.8
# Download all files with .txt extension from remote FTPS Server


###################################
# Define Variables for FTP Server #
###################################
USER=”ftpusername”
PASS=”ftppassword”
FTPSERVER=”ftp.domain.com”
PORT=”991″
LOCALDIR=”$HOME/FTP”

######################################################################################
# For loop to determine file names in FTP Directory, and then Download each of them. #
######################################################################################
cd $LOCALDIR
echo Downloading Files…..
FILES=”$(curl -l –ftp-ssl –insecure –user “$USER:$PASS” ftp://$FTPSERVER:$PORT)”
for f in ${FILES}
do
        curl –ftp-ssl –insecure -O -u “$USER:$PASS” ftp://$FTPSERVER:$PORT/$f
        echo $f
done

################################
# Delete Files Once Downloaded #
################################

# Because not everyone is smart, and blindly executes code, I have commented this useful part out.

#echo Deleting Old Files….
#FILES2=”$(curl -l –ftp-ssl –insecure –user “$USER:$PASS” ftp://$FTPSERVER:$PORT)”
#for f in ${FILES2}
#do
#curl -X “DELE $f” –ftp-ssl –insecure –user “$USER:$PASS” ftp://$FTPSERVER:$PORT
#done


#####################
# Completed Message #
#####################
echo FTPS Transfer Completed!

Automated Script to Upload or put all Files:

#!/bin/sh
# Created by Zwiegnet Linux Admins 2/7/2015
# Version 1.2
# Upload files via FTPS and remove from local directory

###################################
# Define Variables for FTP Server #
###################################
USER=”ftpuser”
PASS=”ftppassword”
FTPSERVER=”ftp.domain.com”
PORT=”991″
LOCALDIR=”$HOME/FTP”


#########################
# Do Not Edit Past Here #
#########################
cd $LOCALDIR
echo Uploading Files…..
FILES=$LOCALDIR/*
for f in ${FILES}
do
       curl –ftp-ssl –insecure –user “$USER:$PASS” -T $f ftp://$FTPSERVER:$PORT
        echo $f
done

##############################
# Delete Files Once Uploaded #
##############################
# Because People blindly execute scripts, I have commented out this part of useful code

#echo Deleting Old Files….
#FILES2=”$(curl -l –ftp-ssl –insecure –user “$USER:$PASS” ftp://$FTPSERVER:$PORT)”
#for f in ${FILES2}
#do
#rm -f $LOCALDIR/*
#done

Hopefully the Open Source community enjoys this article, this took quite a bit of work, but is completely worth it to be secure, using FTPS for file transfers.

Hosted Linux Servers at www.zwiegnet.com/go

Leave a Reply

Your email address will not be published. Required fields are marked *