Search code examples
bashamazon-s3ftpraspberry-pi2

Bash script for FTP file transfer from Raspberry Pi to Amazon S3


I'm trying to transfer .bin files from my Raspberry Pi 2 to an Amazon S3 server using a bash script "connect_ftp_amazon" as follows:

#!/bin/bash

HOST='XX.XXX.XXX.XXX'
USER='my_user'
PASSWD='my_password'
DIR='/s3_folder'
LOCALPATH='/raspberrypi_folder'

ftp -inv $HOST <<EOF
quote USER $USER
quote PASS $PASSWD
cd $DIR
lcd $LOCALPATH
mput *.bin
quit
exit;
EOF

However, when I try to execute it in the terminal window with

chmod a+x connect_ftp_amazon
sudo ./connect_ftp_amazon

I got

ftp: connect: Connection timed out
Not connected.
Not connected.
Not connected.
Local directory now /home/pi/raspberrypi_folder
Not connected.

I guess I'm passing my host and/or user parameters in the wrong format, as it works fine with a Linux server. Could somebody help me to identify what is wrong with my settings?


Solution

  • You cannot connect to Amazon S3 with FTP. You have to use S3 protocol.

    Use aws s3 or s3cmd commands.

    See Uploading files to S3 account from Linux command line.


    Though you can mount S3 bucket to a (Linux) server and setup FTP/SFTP server there. See FTP/SFTP access to an Amazon S3 Bucket.