FTP via BASH

in this morning, i’ve make a simple script for copying files from server A to server B. When i try to use sshles password, my remote-server always asked me a password. i’ve give up configuring sshless password between server A to server B, so i try to use FTP. little bit tricky i think, but this is only the way. Here’s the simple script for uploading file via FTP in bash :

HOST=xxxx
USER=yyyyy
PASS=zzzzzz
cd /backup/backup/db/
pwd
ls -lash
ftp -inv $HOST << EOF

# Call 2. Here the login credentials are supplied by calling the variables.

user $USER $PASS

# change to the FTP directory where you want to put or get
cd /tmp

# Upload A file to FTP server using put

put uji_coba-`date +%Y-%m-%d`.ypt
# or downloading file from ftp server
# get uji_coba-`date +%Y-%m-%d`.ypt
bye
EOF

one days earliear than today with date

today, after christmas, i have a job, copying backup folder to surabaya. My backup format is dir-name-YYYY-MM-DD, and i want to copy all of file in that directory one day earliear from the current date. So, how i do that task ? after reading man pages of date, i’ve got a clue, here it is :

to get 1 day earlier than today, run this command :

date -v-1d +%Y-%m-%d

on my directory format (dir-name-YYYY-MM-DD), i run this command :

scp -r dir-name-$(date -v-1d +%Y-%m-%d) user_dest@xxx.xxx.xxx.xxx:/wew/

DONE!!