Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
Last active October 1, 2019 20:21
Show Gist options
  • Save mttjohnson/fd186a501f5eb79c5a3f95af4a68372c to your computer and use it in GitHub Desktop.
Save mttjohnson/fd186a501f5eb79c5a3f95af4a68372c to your computer and use it in GitHub Desktop.
Automating FTP Commands
HOST="127.0.0.1"
USER="username"
PASSWD="password_transmitted_in_cleartext_via_ftp"
TIMESTAMP_UTF=$(date -u +"%Y%m%dT%H%M%SZ")
TIMESTAMP=$(date +"%Y%m%dT%H%M%SZ")
FILENAME="${TIMESTAMP}-${TIMESTAMP_UTF}.temp"
# Create empty temp file with timestamps in filename
# Change to /myexample/test/directory
# Upload temp file so that file gets creation timestamp
# List the file/directory contents to see the creation timestamp
# Delete the uploaded file
# List the temp file locally
# Display current local and UTC date
# Delete the temp file locally
touch ${FILENAME}
FTP_COMMANDS=$(cat <<FTP_COMMANDS_HEREDOC
ascii
user $USER $PASSWD
prompt
cd /
cd myexample
cd test
cd directory
put ${FILENAME} ${FILENAME}
ls
delete ${FILENAME}
ls
bye
FTP_COMMANDS_HEREDOC
)
echo "${FTP_COMMANDS}" | ftp -n -v $HOST
ls -la ${FILENAME}
date
date -u
rm -f ${FILENAME}
# Change to /myexample/test/directory
# and List the file/directory contents
FTP_COMMANDS=$(cat <<FTP_COMMANDS_HEREDOC
ascii
user $USER $PASSWD
prompt
cd /
cd myexample
cd test
cd directory
ls
bye
FTP_COMMANDS_HEREDOC
)
echo "${FTP_COMMANDS}" | ftp -n -v $HOST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment