After FTP unable to move file to other location

Hi Experts,

I am using below script and facing some problems..

cd /home/user/test
rm ftp://ftp.log
Example: A_Bachfile_09292011.txt
A=`ls -1 "A*.txt"`
compress $A
C=`ls -1 "A*`
 
hostname="test.gmail.com"
user="raju"
Password="******"
 
ftp -n $hostname <<EOF >>ftp.lpg
user=$user
password=$Password
lcd home/user/test
cd target
type binary
put $c
bye
EOF
quit
 
cd /home/user/test
mv $c /home/user/test/archive

Please let me know how to do this, when i tried i face some issues.
and session is not comming out from ftp process.

You say in your title "unable mv file to other location". What exactly does your script do?

rm ftp://ftp.log

You can't run rm on a URL. It only works on local files.

ftp -n $hostname <<EOF >>ftp.lpg
user=$user
password=$Password
lcd home/user/test
cd target
type binary
put $c
bye
EOF
quit

why do you have quit outside of the <<EOF ... EOF block? I think that's supposed to go to the FTP, isn't it?

cd /home/user/test
mv $c /home/user/test/archive

Once you cd, $c is no longer in the same folder as you and 'mv $c ...' will not work.

There's no point cd-ing to that directory when you're giving the full path to the destination anyway. Just leave out the cd entirely.

This is what i am trying, first i have to run data stage job for Aix server and it will generate a file that file will mv with currentdate stamp (PSIC_FIlename_29092011130105.txt) then compress and FTP file and move it archive folder this should done for each step.

#!/bin/sh
# This script will put QIS2 data into the Falt files for PSIC activities.
ScriptOutput=/QIS2FTP/dsclientprod/home/scripts/ScriptRunInfo.txt
StartTime=`date +%d-%m-20%y" "%H:%M:%S`
JobInfoScript=/QIS2FTP/dsclientprod/home/scripts/JobStatus.sh
# for debugging purposes only
set -x
# import my environment
. /QIS2FTP/dsclientprod/home/my.env
weeklyLoadDirectory=/QIS2FTP/dsclientprod/development
# variables
scriptsDirectory=/QIS2FTP/dsclientprod/home/scripts/weekly
ChooseNumber=10
# move to the telematics directory
cd $weeklyLoadDirectory/
today=`date`
echo "START: PSIC starting for $today. Processing"
#start STEP 4
status=`dsjob -report QIS2 PSIC_COUNTRY BASIC | grep status | awk -F= ' { print $2; } ' | awk ' { print $1; } '`;
if [ "x3" = "x${status}" ]
then
dsjob -run -mode RESET -wait -jobstatus QIS2 PSIC_COUNTRY
fi
echo dsjob -run -mode NORMAL -wait -jobstatus -warn 999999999 QIS2 PSIC_COUNTRY
dsjob -run -mode NORMAL -wait -jobstatus -warn 999999999 QIS2 PSIC_COUNTRY
sh $JobInfoScript "PSIC" PSIC_COUNTRY
cd /QIS2FTP/dsclientprod/PSIC/
mv PSIC_Country_DataFile.txt PSIC_Country_DataFile_`date '+%Y%m%d%H%M%S'`.txt
compress PSIC_Country_DataFile*.txt
Cfile=`ls -1 PSIC_Country_DataFile*`
for i in $Cfile
do
#FTP Script
#######################################
#Scripted By Raju B on 14/Sep/2011 #
#Before doing FTP Uncomment Variables #
#######################################
rm /QIS2FTP/dsclientprod/PSIC/FTP.log
FileDate=`date '+%Y%m%d'`
Host_name="r89.gmail.com"
USER_ID="yyyy"
PWD="xxx"
echo "Host Name is : $Host_name" >>FTP.log
echo "User_id is : $User_id"
echo "Password is : $Pwd"
ftp -n $Host_name <<End-Of-Session
user $USER_ID $PWD
lcd /QIS2FTP/dsclientprod/PSIC/
cd /card30/outputs/na/aware/
type binary
put $i
bye
End-Of-Session
#exit;


if [ $? -eq 0 ]
then
echo "Successfully FTP'ed the file from remote server..." >>FTP.log
else
echo "Error has occured while FTP'ing the file from remote server" >>FTP.log
fi
echo "End of the script..." >>FTP.log
#quit;
mv $i /QIS2FTP/dsclientprod/PSIC/archive/
#Here i am getting en error and local directory is will changing here and it is not going to step 5 level
done
##end step 4 return code
echo "STEP 4 FINISHED."
#start STEP 5
status=`dsjob -report QIS2 PSIC_CITY_BASIC | grep status | awk -F= ' { print $2; } ' | awk ' { print $1; } '`;
if [ "x3" = "x${status}" ]
then
dsjob -run -mode RESET -wait -jobstatus QIS2 PSIC_COUNTRY
fi
echo dsjob -run -mode NORMAL -wait -jobstatus -warn 999999999 QIS2 PSIC_COUNTRY
dsjob -run -mode NORMAL -wait -jobstatus -warn 999999999 QIS2 PSIC_COUNTRY
sh $JobInfoScript "PSIC" PSIC_CITY
cd /QIS2FTP/dsclientprod/PSIC/
mv PSIC_Country_DataFile.txt PSIC_City_DataFile_`date '+%Y%m%d%H%M%S'`.txt
compress PSIC_City_DataFile*.txt
Cfile=`ls -1 PSIC_City_DataFile*`
for i in $Cfile
do
#FTP Script
#######################################
#Scripted By Raju B on 14/Sep/2011 #
#Before doing FTP Uncomment Variables #
#######################################
rm /QIS2FTP/dsclientprod/PSIC/FTP.log
FileDate=`date '+%Y%m%d'`
Host_name="r89.gmail.com"
USER_ID="yyyy"
PWD="xxx"
echo "Host Name is : $Host_name" >>FTP.log
echo "User_id is : $User_id"
echo "Password is : $Pwd"
ftp -n $Host_name <<End-Of-Session
user $USER_ID $PWD
lcd /QIS2FTP/dsclientprod/PSIC/
cd /card30/outputs/na/aware/
type binary
put $i
bye
End-Of-Session
#exit;


if [ $? -eq 0 ]
then
echo "Successfully FTP'ed the file from remote server..." >>FTP.log
else
echo "Error has occured while FTP'ing the file from remote server" >>FTP.log
fi
echo "End of the script..." >>FTP.log
#quit;
mv $i /QIS2FTP/dsclientprod/PSIC/archive/
done
##end step 5 return code
echo "STEP 5 FINISHED."
set +x

And in what way does it not work? What does it do?

1) The "cd" and "lcd" commands within a ftp session do not persist outside that session. It will be better to issue a shell "cd" before starting the ftp script and then you won't need the "lcd" in the ftp script ... and the current directory will be correct when you come to issue the "mv".

2) In most modern shells the environment variable $PWD is reserved and holds the value of the current working directory. Strongly advise you use a different name for the environment variable to hold your ftp password.

3) Beware that shell environment varable names are case-sensitive. Thus $Pwd and $PWD are different environment variables. Similarly from post #1 $C and $c .