How to know number files transferred

Hi,

I am transferring files from our local server to remote server using FTP command in a shell script.

I am using a the following code,

FTPFILE="ercchk*.txt"
mput $FTPFILE

can any one help me out in calucalating the number of files transfered.
help in this regard is highly appreciated.

regards,
Azaz Ali.

ls -1 ercchk*.txt|wc -l

On my AIX box, ftp output a message from every file tranfered :

$ ftp localhost
Connected to loopback.
220 KLOGI810 serveur FTP (Version 4.1 Fri Mar 29 22:11:06 CST 2002) pr�t.
Name (localhost:user): 
331 Mot de passe requis pour user.
Password:
230 Utilisateur user connect�.
ftp> cd TMP    
250 Ex�cution de la commande CWD termin�e.
ftp> lcd TMP/FTP
Local directory now /home/user/TMP/FTP
ftp> prompt off
Interactive mode off.
ftp> mget F*.DAT
200 Ex�cution de la commande PORT termin�e.
150 Etablissement de la connexion de donn�es pour F0.DAT (0 octets).
226 Transfert termin�.
200 Ex�cution de la commande PORT termin�e.
150 Etablissement de la connexion de donn�es pour F10.DAT (0 octets).
226 Transfert termin�.
200 Ex�cution de la commande PORT termin�e.
150 Etablissement de la connexion de donn�es pour F11.DAT (0 octets).
226 Transfert termin�.
ftp> bye
221 Au revoir.

If you ftp output is similar you can do something like this :

ftp xxxxxxx >ftp.log 2>&1
echo "#Transfered files : $(grep -c '^226' ftp.log)"

Jean-Pierre.

Hi,

First i would like to thank you for your replies.

My FTP specific code as follows,

PUTHOST=xxxxxx.xxx.xxx.xxx
PUTUSER=xxxxxxxxxx
PUTPASSWD=xxxxxxxx
FTPFILE="xxxxxx*.txt"
ftp -n -v $PUTHOST << EOF
quote USER $PUTUSER
quote PASS $PUTPASSWD
cd xxxxxxx
lcd $xxxx
mput $FTPFILE
quit
EOF

I am a new comer in Unix world so doen't know much about it. Please help me out in this,
ls -1 xxxxxx*.txt|wc -l

the above code gives only the no. of files with xxxxxx*.txt but i don't think so these give the number of files transfered.

Your help in this regard is highly appreciated.

Regards,
Azaz Ali.

its assumed that files of type xxx*.txt are being transferred through the script and thats an indirect way of identifying how many files are going to be transferred with the ls -1 xxx*.txt | wc -l option....

another option has mentioned here to grep from the logs after ftping...

you do use multiple file transfer and why isnt that interactive prompting is not turned off by specifying -i option?

Hi Madan,

First i would like to thank you for your reply.
I don't have much knowledge on both shell scripting as well as on FTP.
I just came to know by seeing the reply that -i option is used to turn off tthe interactive scripting.
Can you please suggest me the code we should be added in the code which i have sent to 1.Log files whenever the script is executed and 2.total number of files transfered.

Regards,
Azaz.

here it is,

ftp -n -i -v <<EOF >logFile
#ftp commands
EOF

you would have the ftp log information in the logFile
and grep for 226 Transfer complete message

You can do something like this :

PUTHOST=xxxxxx.xxx.xxx.xxx
PUTUSER=xxxxxxxxxx
PUTPASSWD=xxxxxxxx
FTPFILE="xxxxxx*.txt"
FTPLOG=ftp.log
FTPFILES=ftp_files.log

ls $FTPFILE > $FTPFILES
FilesCount=$(wc -l < $FTPFILES)
echo "Number of files to transfert : $FilesCount"

ftp -n -v $PUTHOST 2>&1  << EOF | tee $FTPLOG
quote USER $PUTUSER
quote PASS $PUTPASSWD
cd xxxxxxx
lcd $xxxx
mput $FTPFILE
quit
EOF

Jean-Pierre.

Hi Jean and Madan,

Thank you very much for sparing time and giving two different solutions.

Sorry for asking small questions. I more in my mind is,

If i use the below code where should i use the grep command to calculate the number of files?
ftp -n -i -v <<EOF >logFile
#ftp commands
EOF

I have a doubt that whether it should be used inside or outside the EOF

Regards,
Azaz Ali.

The code betwen lines <<EOF and EOF is the input for the ftp command.

ftp -n -i -v <<EOF >logFile
#ftp commands
EOF

fileCount=$(grep -c '^226' logFile)

Jean-Pierre.