LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Shell Script Help (https://www.linuxquestions.org/questions/linux-newbie-8/shell-script-help-938106/)

shivaprasath143 04-04-2012 12:11 PM

Shell Script Help
 
Hi Guys,

Can someone help me on ftping files via shell script please ?

i have created a script but its getting st-rucked after connecting to
the ftp location (i can see that logs).

Please see below i have pasted script and log.

#SCRIPT#
.env

set -a

##################
#Local Variables
##################

LOGDIR=/logs
LOGFILE=ftp.log
PICKUPDIR=/alpha/beta/
DROPDIR=/home/shiva/
DATE=`date +%Y-%m-%d`
GATEWAY=12.25.30.25
USERID=shivaprasath
PASSWD=cmm1234

###########
#FUNCTIONS#
###########

#function to pull Files

ftp_copy ()
{
ftp -in $GATEWAY
user ${USERID} ${PASSWD}
cd ${PICKUPDIR}
lcd ${DROPDIR}
mget MP3_${DATE}*
bye
!
} >> $LOGDIR/$LOGFILE

#############
#Main Script#
#############

echo "Starting Files ftp: \c" >> $LOGDIR/$LOGFILE
date >> $LOGDIR/$LOGFILE
ftp_copy
echo "Ending Files ftp: \c" >> $LOGDIR/$LOGFILE

wait

date >> $LOGDIR/$LOGFILE
exit 0

#End of Script#




# ftp.log#

Starting Files ftp: Wednesday, 4 April 2012 16:21:43 BST
Connected to 12.25.30.25.
Welcome to the FTP Site
Remote system type is Windows_NT.
ftp>
ftp>


Regards,
Shiva

jf.argentino 04-05-2012 06:14 AM

When you need to "discuss" through network with shell, you have to use netcat. But, just for ftp transfers, I think you could use "ftpput" and "ftpget"

lithos 04-05-2012 07:47 AM

Hi,

probably your FTP function is not getting what it's supposed to:
Code:

#!/bin/sh
HOST='ftp.users.qwest.net'
USER='yourid'
PASSWD='yourpw'
FILE='file.txt'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0

This is an example of working one from here.


Just for an option, if you could use LFTP instead of Ftp, that would solve you much trouble with FTP scripting.

good luck

David the H. 04-05-2012 02:41 PM

please use [code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.


QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.

http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes


Environment variables are generally all upper-case. So while not absolutely necessary, it's good practice to keep your own user variables in lower-case or mixed-case, to help differentiate them.


$(..) is highly recommended over `..`


All times are GMT -5. The time now is 01:28 AM.