removing files after ftping

Hi All,

I'm trying to write script to ftp some files and then need to remove these files from server.
Is there any way to keep the condition that the file should be removed only after successfully transfered to the destinatino server?
If in case, the file isn't been transferd, it should not be removed.

Thanks in advance.

Regards,
im_new

Can anyone plz help/advise?

did you try to check the status of transfer using '$?' ?

Hi manikantants,
I'm dealing with ftp for the first time. I'm not sure how this status check is done? Can u plz let me know.. Even, I'll try to search for it.
Thanks

'$?' will give the exit status of previous command.
So in case of ftp also you can check this exit status. If it is not equal to zero, that means ftp was not successfull.

following lines may help you. I haven't tested this.
Please test it properly before using.

ftp -n 255.255.255.255 << EOF
user username
password
put filename
bye
EOF

if [ $? -eq 0 ]
then
#do the required on successfull transfer
else
#do the required on failure
fi

Thanks a ton!!! :slight_smile: