LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   FTP script help (https://www.linuxquestions.org/questions/linux-newbie-8/ftp-script-help-823090/)

josephf 07-30-2010 01:12 PM

FTP script help
 
need help to write a script to ftp a file and get an email confirmation or failure sent out.

druuna 07-30-2010 01:17 PM

Hi,

What have you tried and which problems did you encounter? Any details?

We are willing to help, but I don't think you can expect us to deliver a script/program from scratch :)

josephf 07-30-2010 01:27 PM

Have the ftp working need to know how to send an email to let me know if it succeeded or not. Here is the script so far:
#!/bin/ksh
HOST='xxx.xxx.xxx.xxx'
USER='username'
PASSWD='passwd'
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd /directory

prompt
mput file.txt

quit
END_SCRIPT
exit 0

josephf 07-30-2010 01:28 PM

I would like to send email using mutt as well, if possible.

druuna 07-30-2010 02:25 PM

Hi,

I don't use mutt, but this will give you an idea (I hope):
Code:

#!/bin/bash

HOST='127.0.0.1'
USER='username'
PASSWD='password'
FILE='filename'
TARGDIR='targetdirectory'
STATUSFILE="/tmp/ftpStatus.out"
MAILUSER="joe.doe@home.nl"

/usr/bin/ftp -in $HOST 1>/dev/null 2>$STATUSFILE <<END_SCRIPT
user $USER $PASSWD
cd $TARGDIR
put $FILE
bye
END_SCRIPT

if [[ -s $STATUSFILE ]]
then
  # ftp has failed
  echo "fail code goes here"
#  cat $STATUSFILE | mailx -s "ftp transfer has failed!" $MAILUSER
else
  # ftp succeeded
  echo "succeed code goes here"
#  mailx -s "ftp transfer has succeeded!" $MAILUSER
fi

rm $STATUSFILE

Both mailx commands are commented out, if you have mailx on your system it should work and you can remove the hash.

Hope this helps.

josephf 07-30-2010 02:29 PM

Thanks, I'll test it out and let you know how it goes.


All times are GMT -5. The time now is 06:34 AM.