Get file from source server and delete the ftp file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get file from source server and delete the ftp file
# 1  
Old 10-16-2005
Question Get file from source server and delete the ftp file

Hi there Everyone,

I need some help/information/advise for the following questions:

I'm writing the following script:

#Beginning of the script

ftp -n <source server> > ${log_dir}/test_get.log << END
user <user_name>@<IP Address> <passwd>
verbose
bin
!echo "'List Files Before Getting A0 Data'"
ls
!echo "'Getting A0 Data'"
lcd /usr/mir7/dmail/data # Destination
mget A0*
bye
END

ftp -n <source server> > ${log_dir}/test_get.log << END
user <user_name>@<IP Address> <passwd>
!echo "'List All A0 Data"
dir A0*
bye
END

echo "List A0 Files in Destination" >> ${log_dir}/test_get.log
ls ltr A0* | grep "A0*" >> ${log_dir}/test_get.log

#The End

After getting the file from the source server I would like to delete the file from the source server but only the files which I have ftp to my server. Is there anyway to do it? I understand ftp do not understand "if...then...else" or "while" statements. How can I go about doing it? Any ideas/ advise/ help will be much appreciated.

Thanks.

wee
# 2  
Old 10-17-2005
This is what you want.
Code:
#!/usr/bin/ksh
ftp -ivn <<EOJ >> /tmp/some_log_file
open server_name
user username password
asc
dir A0* /tmp/A0.lst
quit
EOJ
## at this point, we have the list of A0* files with us

echo "open server_name" >> /tmp/batch.out
echo "user user_name pass_word" >> /tmp/batch.out

awk '{print $NF}' /tmp/A0.lst | while read file; do
echo "get $file" >> /tmp/batch.out   #we construct a ftp batchfile that will
echo "del $file" >> /tmp/batch.out   #delete a file after it transfers it to
done                                          #our end
echo "bye" >> /tmp/batch.out
rm /tmp/A0.lst
ftp -ivn < /tmp/batch.out >> /tmp/some_log_file

# 3  
Old 10-17-2005
hi blowtorch,

let me use your script and try it out. i will reply u once it has been tested. thanks man.

wee
# 4  
Old 10-17-2005
hi blowtorch,

it works!! thanks so much for the help.

wee
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Update/Download file from FTP server to UNIX Server

HI Guys, I want to download files from FTP Server to my Unix server. I have tried , buy No Luck . Below Command i have tried. 1-Wget - Error "wget' not found" 2.ftp -n $HOST ...Not Working. 3.scp -i ftp://user:passowrd@hostname:21/ran/on/test.txt Any Suggestion (2 Replies)
Discussion started by: pareshkp
2 Replies

2. Shell Programming and Scripting

List the file names available on FTP server before selecting the required file

Below is my script code.which shows the environment name and then fetch the file from the ftp server but I am facing one issue.The script should be run in both way.We can pass the arguments with script and select the environment name then file name.Here the issue is I am not able to list the files... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

3. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

4. 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

5. Shell Programming and Scripting

preserving the timestamp of a file when copied from remote server to local server using ftp

Hi, I need to copy few files from remote server to local server. I write a shell script to connect to the remote server using ftp and go to that path. Now i need to copy those files in the remote directory to my local server with the timestamp of all those files shouldnt be changed. ... (5 Replies)
Discussion started by: arunkumarmc
5 Replies

6. UNIX for Dummies Questions & Answers

Copying dir (and sub dir) file names from ftp server to txt file in diff server

Hey all, i want to copy only the file names from an ftp server (directory and all sub directory) to a text file in another server (non ftp), i.e. i want to recursively move through directories and copy only the names to a text file. any help is appreciated...thank you in advance (1 Reply)
Discussion started by: deking
1 Replies

7. Shell Programming and Scripting

Rsync help - unable to delete the Source file

Hi All, I am facing problem deleting Source while using the rsync command. rsync --include=*`date --date="-1 day" \+\%Y\%m\%d`* --include=*`date +\%Y\%m\%d`* --exclude=* --delete-after -auvb -e ssh USER@SERVER:SOURCE DESTINATION However the sync happens but not the deletion of the source... (1 Reply)
Discussion started by: amitkhiare
1 Replies

8. Shell Programming and Scripting

Dowloading a File from FTP Server to a local Server where User Id's are different

Hi, The Setup is like this. I'm connecting to Unix machine from my local machine. After connecting to Unix M/c, i need to connect FTP server. Am successful in connecting to FTP server, but am not able to download the file from the ftp server to my local machine. I have different user id's and... (1 Reply)
Discussion started by: ranjith_taurean
1 Replies

9. Shell Programming and Scripting

how to move a file from one server to another server using FTP in shell script?

I have a file --> file1.txt i need to copy this file to another server using FTP....the 2 servers are server1 and server2..may i know how to write a script that can do this? thanks in advance! Im a newbie to this... (4 Replies)
Discussion started by: forevercalz
4 Replies

10. UNIX for Dummies Questions & Answers

ftp copy: preserve source file date stamp

Is there any way to preserve a file's create/mod date stamp when it is "put" via ftp (or even using Fetch) to a Win2K server and a SunOS 5.8 server? For example, if I copy a file with a create/mod date of "01/15/2005 3:36 PM" to my Win2K or SunOS ftp server, the date stamp will change to the... (5 Replies)
Discussion started by: cassj
5 Replies
Login or Register to Ask a Question