After FTP unable to move file to other location


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting After FTP unable to move file to other location
# 1  
Old 09-28-2011
Bug After FTP unable to move file to other location

Hi Experts,

I am using below script and facing some problems..

Code:
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.


Moderator's Comments:
Mod Comment Instead of formatting each line on its own learn how to use [CODE] tags correctly.

Last edited by rajubollas; 09-29-2011 at 02:57 AM..
# 2  
Old 09-28-2011
You say in your title "unable mv file to other location". What exactly does your script do?

Code:
rm ftp://ftp.log

You can't run rm on a URL. It only works on local files.
Code:
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?

Code:
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.
# 3  
Old 09-29-2011
Afer FTP unable mv file to other location

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.
Code:
#!/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


Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

 

Last edited by Franklin52; 09-29-2011 at 03:53 AM.. Reason: Please use code tags and indentation
# 4  
Old 09-29-2011
Quote:
Originally Posted by rajubollas
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.
And in what way does it not work? What does it do?
# 5  
Old 09-30-2011
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 .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Get all the files from a FTP location with previous week's dates in the file names using Linux

I have a weird requirement where I have to get the files from a FTP(Lets say FTP1) location and place it on my current FTP(Lets say FTP2) location. The issue is, these are daily files (in a pattern Sales_YYYYMMDD_report.csv) and are placed every day on FTP1 and my process usually runs on Monday(eg.... (2 Replies)
Discussion started by: dhruuv369
2 Replies

2. Shell Programming and Scripting

How to move a file in ftp command to other location?

hi, when i do ftp from unix to laptop which is running a windows os, it lands in a root folder. can i move a file from this root ftp folder to any other location in my laptop say , c:\files\ folder? i used rename command inside ftp , but it says incorrect parameter. (5 Replies)
Discussion started by: Little
5 Replies

3. UNIX for Advanced & Expert Users

Want to download a latest file with current date from FTP location

Dear Friends, I need help to write a shell / perl script to download the files from FTP location, having different file names (date inside the file name). Example: Mar 5 09:24 cfx_03052013_return_file.txt Mar 6 02:13 cfx_03062013_return_file.txt Mar 7 06:40... (3 Replies)
Discussion started by: Praveen Pandit
3 Replies

4. Shell Programming and Scripting

How to find a word and move it a specific location in xml file using perl?

Hi friends, I have one XML file having below structure :- INput XML file :- <?xml version="1.0" encoding="UTF-8"?> <START> <A=value1> <attr name1="a1"> </A> <B=value2> <attr name2="b1"> <attr name3="c1"> </B> </START> output xml file should be === (3 Replies)
Discussion started by: harpal singh
3 Replies

5. Shell Programming and Scripting

How to move the older than 30 file to another ftp server

Hi All I need to move the older than 30 days file to another ftp server. I have source structure like this Files folder Folder1 Folder2 Folder3 I need to create same Target structure and I need to move the older than 30 day file to another ftp server, can you please suggest me how I develop... (1 Reply)
Discussion started by: murari83.ds
1 Replies

6. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

7. Shell Programming and Scripting

Move files from one location to another

Hi, I wanted to check how to move files from one location to another based some particular date. Example I want to move /data/NewJersey folder to /home/scripts/NJ ( including all the files and subfolders within it ), but only which are older than say 8th February 2010. script , awk, sed (... (4 Replies)
Discussion started by: rudoraj
4 Replies

8. Shell Programming and Scripting

ftp: get list of file to get. Retrieve and move them

Hi, I need to get multiple files from an ftp server. Once the files have been downloaded, I need to move them to a different directory on the ftp server. I don't know of a command that would enable me to get a file and then move it (assuming I don't know the exact file name) within ftp. I think... (10 Replies)
Discussion started by: bbabr
10 Replies

9. UNIX for Dummies Questions & Answers

Unable to copy or move file

I am trying to move a file that is in the root directory. I suspect it is an old file created by someone when the system was installed. I am testing accessing the file by doing a copy but the command does not find the file. I am operating as root. We are HP-UX B.11.23 I do long listing and... (3 Replies)
Discussion started by: phcorn
3 Replies

10. Shell Programming and Scripting

how to put file from one ftp to another ftp location

hi, I have one file located in ftp.I want to place that file in different ftp location. Up to now i am doing it manually using get command and copying that file in to my local system and then putting that file in different ftp using put command. now i want to automate that using shell... (1 Reply)
Discussion started by: prasee
1 Replies
Login or Register to Ask a Question