LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-12-2013, 11:29 AM   #1
psudo
LQ Newbie
 
Registered: Aug 2013
Posts: 3

Rep: Reputation: Disabled
FTP Bash script issue


Ive got a bash script put together and its not quite working. It is as follows:

#!/bin/sh
HOST="ftp.com"
USER="testuser"
PASSWD="secure_password"
FILE=/test.txt

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd target_directory
put $FILE
bye
END_SCRIPT
exit 0

To which I get the following output:

./ftp_upload.sh
Trying 99.99.99.99...
/test.txt: Error on output file.

When I test this script manually (Entering each command in turn) it works.

In new to scripting. I basically pulled this of the net and im not sure what is failing. Any thoughts?
 
Old 08-12-2013, 11:47 AM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
is your test.txt file really in the root dir? (/)
 
Old 08-12-2013, 11:49 AM   #3
psudo
LQ Newbie
 
Registered: Aug 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
That path was for demonstration purposes only. The real script has the correct path. and the test file is indeed located there

Thanks for the response!
 
Old 08-12-2013, 12:13 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
ftp is antiquated, insecure and not very flexible.

is there any way you can use scp/sshfs instead (they are easily scriptable when using with private-key-encryption) ?

Last edited by schneidz; 08-12-2013 at 12:15 PM.
 
Old 08-12-2013, 04:30 PM   #5
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by psudo View Post
Ive got a bash script put together and its not quite working. It is as follows:

#!/bin/sh
HOST="ftp.com"
USER="testuser"
PASSWD="secure_password"
FILE=/test.txt

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd target_directory
put $FILE
bye
END_SCRIPT
exit 0

To which I get the following output:

./ftp_upload.sh
Trying 99.99.99.99...
/test.txt: Error on output file.

When I test this script manually (Entering each command in turn) it works.

In new to scripting. I basically pulled this of the net and im not sure what is failing. Any thoughts?
as im still semi new to scripting, what are the quote USER for?

also here is a lftp script i have from a while back that works great. now it does not use a secure p/w because well its FTP

Code:
#!/bin/bash

startdate="`date +%Y-%m-%d-%a-%H.%M.%S`"
dow=`date +%A`
tarfilename=foo-${dow}
HOMEDIR="$HOME"
logname=${HOMEDIR}/logs/${startdate}-FTPBackup.log
enddate1="`date +%Y-%b-%d-%a-%H.%M.%S`"

url1=ftp.foo.com

# Change the NAS device's directory to where you want the files sent
############################################################

backdir1=disk1/some/place
LDIR=`pwd`
username=user
password=password
cd ${HOMEDIR} 

lftp1()

{
if [ "${NO_KILL}" != "true" ]
then
	lftp -e "set ftp:passive-mode on && cd ${backdir1} && put ${NEWTAR} && bye" -u ${username},${password} ${url1}
else
	lftp -e "set ftp:passive-mode on && cd ${backdir1} && put /tmp/${tarfilename}.tar.bz2 && bye" -u ${username},${password} ${url1}
fi

}

TAR()

{

	tar cvjf /tmp/${tarfilename}.tar.bz2 -X ${HOMEDIR}/excludes.conf ${HOMEDIR}  >> ${logname} 

}

checkTar ()

{

tar tfj /tmp/${tarfilename}.tar.bz2 &> /tmp/tar2; bzerr="$?"; echo $bzerr > /tmp/bz-check.list

echo "Verifying compressed data." | tee -a ${logname}
VERSTAT=`cat /tmp/bz-check.list`

if [ ${VERSTAT} -eq 0 ]
then
	echo "Verification of compressed data was successfull." | tee -a ${logname}
else
	echo "Compressed data appears to be corrupt.  Error ${VERSTAT}." | tee -a ${logname}
	exit 1
fi

    echo "Encrypting ${tarfilename}.tar.bz2" | tee -a ${logname}
    openssl des3 -a -salt -in /tmp/${tarfilename}.tar.bz2 -out /tmp/${tarfilename}.tar.bz2.enc -pass pass:somepasswordhere
    echo "${tarfilename}.tar.bz2.enc Encrypted" | tee -a ${logname}
	NEWTAR=/tmp/${tarfilename}.tar.bz2.enc

# to decrypt: openssl des3 -a -d -salt -in 2011-12-20.tar.bz2.enc -out 2011-12-20.tar.bz2 -pass pass:somepasswordhere

}

#Start the Ftp backup log
echo "AutoFTP backup script started ${startdate}" > $logname

### Checking for exclueds file, the adding file types to ignore
### make sure excludes.conf exists or tar command will blow up
### checks for and adds entries to excludes.conf
EXCLUDES=(
         *.tar
         *.tgz
         *.bz2
         *.bz
         *.google*
         *.mozilla*
         *.openoffice*
         *.DCOP*
         *.adobe*
         *.gconf*
         *.gnome2*
         *.mcop*
         *.thumbnail
         *.kde*
	 *Desktop*
         )

EXCLUDENUM=${#EXCLUDES[@]}
echo $EXCLUDENUM

[ -f $HOME/excludes.conf ] || touch $HOME/excludes.conf

for ((i=0; i<$EXCLUDENUM; i++))
do
   grep -w ${EXCLUDES[i]} excludes.conf
   EXERR=$?
   if [ $EXERR -eq 0 ]
   then
        echo "${EXCLUDES[i]} already in excludes.conf"
   else
        echo "adding ${EXCLUDES[i]} to excludes.conf" >>${logname}
        echo "${EXCLUDES[i]}" >>excludes.conf
   fi
done

### Code to clean up /tmp of old failed backups
#####################################
### The sed command will add a '- ' to the front of each of the
### lines in created in excludes.conf and put them in
### excludes.txt for the rsync command to use below.

if [ ! -f ${HOMEDIR}/excludes.txt ]
then
        sed 's/^/- /' excludes.conf > excludes.txt
        echo "Creating excludes.txt to be used by rsync." >> ${logname}
fi

### Cleaning up /tmp to prevent running out of storage space
#####################################

find /tmp/*.bz2 -mtime +2 -exec rm {} \;

### Call to create tarball
#######################################

echo "Compressing contents into backup file ${tarfilename}.tar.bz2" >> ${logname}
TAR
tarend="`date +%Y-%m-%d-%a-%H.%M.%S`"
echo "Backup tar file created ${tarend}" >> ${logname}

### Check and verify tarball then encrypt
#######################################
if [ "${NO_KILL}" != "true" ]
then
	checkTar
fi

### Start the FTP transmission
#######################################

echo "Starting FTP1 transmission ${startdate}" >> ${logname}
lftp1
if [ $? -ne 0 ]
then
	echo "FTP1 transmission failed" >> ${logname}
else
	echo "FTP1 transmission complete to remote computer at ${url1}"  >> $logname
fi

### Cleaning up tarballs

rm -rf /tmp/${tarfilename}.tar.bz2
rm -rf ${NEWTAR}

### Notes for e-mail
### yum install postfix
### cd /var/spool/postfix
### mkfifo pickup
### service postfix restart
### chkconfig postfix on	###this will set postfix to start on bootup###
### uncomment the following line to send e-mail everytime the script runs
# mailx -s "rsync backup log" <e-mail_addres@here.com> < $log
mailx -s "ftp logs ${license}" <e-mail_address@here.com> < ${logname}
echo "mailx -s "ftp logs ${license}" <e-mail_address@here.com < ${logname}" << ${logname}

exit;
that should help
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script problem with ftp session exiting the script early edomingox Programming 5 02-23-2010 05:39 AM
ftp bash script idgeitman Linux - Newbie 1 04-29-2008 04:03 PM
FTP Bash script Elguapo Programming 2 06-07-2007 01:26 PM
bash script AND ftp bokini Linux - General 2 01-04-2006 04:33 PM
how to while in a ftp bash script dezeque Programming 3 06-12-2004 04:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration