Shell Scripting for creating ftp and transfer file

Dear All,

We run backup script to update backup file every hour.

I want to create a script, which transfer these files in another server using ftp as new backup file created every hour. Files should be stored with a unique name for every hour(e.g 20130708_13:00 , 20130708_14:00 and so on) and after completion of 12 hours these files should be deleted.

Please let me know how can I create script for that.

It would be very thankful l if anybody help me on this.

Please check similar posts at the bottom of this page. You should get some idea on the approach.

some ideas for you.

#tar the files into one file
FILE=backup_`date +%Y%m%d_%H%M`.tar.gz
tar cvf - FOLDER|gzip > $FILE

#ftp the file to another server

HOST='ftp.users.qwest.net'
USER='yourid'
PASSWD='yourpw'

ftp $HOST <<END_SCRIPT
user $USER
$PASSWD
put $FILE
quit
END_SCRIPT
exit 0

I made below script, I jsut wnat to make ftp connection and put file...but it not working....it is asking me for password and does not transfer file automatically

#!/usr/bin/expect -f
HOST='10.32.1.153'
USER='uninet\cacti.ftp'
PASSWD='cacti12345'

ftp $HOST <<END_SCRIPT
user $USER
$PASSWD
put a.txt
quit
END_SCRIPT
exit 0
~

You should be running it in shell not expect

Change the first line to

#!/bin/bash
HOST='10.32.1.153'
USER='uninet\cacti.ftp'
PASSWD='cacti12345'

ftp $HOST <<END_SCRIPT
user $USER
$PASSWD
put a.txt
quit
END_SCRIPT
exit 0

Output

[psaini@ls2mutcactisv1 comverse_mmsc]$ sudo sh pre_test
Password:Name (10.32.1.153:psaini):
Login incorrect.
Login failed.
?Invalid command

Its again not working....see what output i am getting when I run script

your script is not sending your password ... see correction below ...

#!/bin/bash
HOST='10.32.1.153'
USER='uninet\cacti.ftp'
PASSWD='cacti12345'

ftp $HOST <<END_SCRIPT
user $USER $PASSWD
put a.txt
quit
END_SCRIPT

exit 0

below output I am getting whn I chnaged script according to you...its not taking password automatically

[psaini@ls2mutcactisv1 comverse_mmsc]$ sudo sh pre_test
Password:Name (10.32.1.153:psaini):

try again ...

#!/bin/bash
HOST='10.32.1.153'
USER='uninet\cacti.ftp'
PASSWD='cacti12345'

ftp -in $HOST << END_SCRIPT
user $USER $PASSWD
put a.txt
quit
END_SCRIPT

exit 0

Now it is showing me below error:

Login incorrect.
Login failed.
Please login with USER and PASS.
Passive mode refused.

ever considered using a .netrc file ?

My 2 cents...

is the remote server a windows box?

if yes, does your ftp process work on the command line by itself? what is the process you take to get this going?

if no, you need to give the proper user account as recognized by that box (i.e., cacti.ftp instead of uninet\cacti.ftp).

if not a windows box and the user account given is what is actually needed, try ...

#!/bin/bash
HOST='10.32.1.153'
PASSWD='cacti12345'

ftp -in $HOST << END_SCRIPT
user 'uninet\cacti.ftp' 
pass $PASSWD
put a.txt
quit
END_SCRIPT

exit 0

Or SFTP? :slight_smile:

Hi,
Server is not windows server. It is a Backup system VMAX (EMC).

Also from command line I login throug uninet/cacti.ftp instead of cacti.ftp

---------- Post updated at 05:50 AM ---------- Previous update was at 12:49 AM ----------

Login incorrect.
Login failed.
Passive mode off.
Please login with USER and PASS.
ftp: bind: Address already in use

Now, I am getting this error