Get the most recent file from a remote server


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Get the most recent file from a remote server
# 1  
Old 09-26-2006
Get the most recent file from a remote server

Hi,
This is an FTP related query.I hvae 2 files in a remote server with the timestamp attached to it.
FilenameYYYYMMDDHHMMSS.EXT.
I need to extract both the fileswith the most recent timestamp using the FTP script
I have used :

ftp Servername
blah blah....

MOST_RECENT_FILE1=`ls -1t ${FTP_OUTPUT_DIR}${FTP_OUTPUT_FILE1}* | head -1 `
get ${MOST_RECENT_FILE1} ${FTP_INPUT_DIR}${FTP_INPUT_FILE1}.EXT



The parameter names speak for themselves.

I am unable to extract the most recent file using ls and head and i get the message FILE NOT FOUND.
Is there an alternative ?

Thanks,
# 2  
Old 09-26-2006
one way:
  1. use either ftp's 'ls' or 'dir' to spool the listing of file in a given remote directory to a local file
  2. 'massage' the listing of the remote files on the local machine - using UNIX utilities to determine the 'newest' file based on the filename time encoding
  3. once the 'newest' file is determined - reconnect to the remote machine and 'get' it.
# 3  
Old 09-26-2006
Thanks for the reply.
I did not understand what you mean by 'massage the listing'.
there are numerous files in the remote directory and I cannot get all of them into the local machine and then pick the recent one.
I need to pick the recent file in the remote and get only that file.
Please let me know if you have any questions.
# 4  
Old 09-26-2006
Quote:
Originally Posted by anujairaj
Thanks for the reply.
I did not understand what you mean by 'massage the listing'.
there are numerous files in the remote directory and I cannot get all of them into the local machine and then pick the recent one.
I need to pick the recent file in the remote and get only that file.
Please let me know if you have any questions.
doing 'man ftp' yields the following for the ftp's "ls" command:
Code:
     ls [ remote-directory | -al ] [ local-file ]
           Prints an abbreviated listing of  the  contents  of  a
           directory  on  the remote machine. If remote-directory
           is left unspecified, the current working directory  is
           used.

           The -a option lists all entries, including those  that
           begin  with  a dot (.), which are normally not listed.
           The -l option lists files in long format, giving mode,
           number of links, owner, group, size in bytes, and time
           of last modification for each file. If the file  is  a
           special  file,  the  size  field  instead contains the
           major and minor device numbers rather than a size.  If
           the  file  is a symbolic link, the filename is printed

get the 'listing' of the direcotry on the 'remote' host.
spool that listing to the 'local' machine's file.
'massage' the listing on the local machine to determine the 'newest' file.
ftp 'get' the "newest" file from the remote machine.
# 5  
Old 09-27-2006
Got it.
But it is a pretty crude method.
Liste the files on the local machine.
sorted and got the most recent file.
Again FTP'ed to the remote server and did a 'get' to get the recent file.
I wonder if there is a way to do it in one shot.
# 6  
Old 09-27-2006
You don't have to break the ftp connection. You can use the "!" to run shell commands on your local machine when you determine the latest file.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script connect to remote server, not find files and exit only from remote server, but not from scrip

I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies

2. Shell Programming and Scripting

Sudo connect to a remote server and execute scripts in remote server

Hello Every one!! I am trying to write a shell script which will connect to a remote server and execute scripts which are at a certain path in the remote server. Before this I am using a sudo command to change the user. The place where I am stuck is, I am able to connect to the... (6 Replies)
Discussion started by: masubram
6 Replies

3. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

4. Shell Programming and Scripting

How to create a file in remote server from local server?

hi, can anyone tell me how can i store the names of a file that are in remote server to a file and then get the file that contains the name in local server? there is a remote server where 5 files are present , say a.txt b.txt c.txt d.txt e.txt i want to write a script in my local... (4 Replies)
Discussion started by: Little
4 Replies

5. Shell Programming and Scripting

Parse file from remote server to calculate count of string existence in that file

Hi I need to parse the file of same name which exist on different servers and calculate the count of string existed in both files. Say a file abc.log exist on 2 servers. I want to search for string "test" on both files and calculate the total count of search string's existence. For... (6 Replies)
Discussion started by: poweroflinux
6 Replies

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

7. Shell Programming and Scripting

Use cURL in shell script and get most recent file from remote server using SFTP

I have been trying to implement the following shell script -- sftp to remote server get list of files in the directory sftp get the most recent listed file exit This script will be scheduled to be executed everyday using CRON or CONTROL-M and the need is to have absolutely no human... (7 Replies)
Discussion started by: toobrown1
7 Replies

8. UNIX for Dummies Questions & Answers

Re: Recent acquired HP E-45 Sco -Unix Server

I am studying IT - CIS in school. I do not know to much programming (a little javascript maybe). I have Ethernet for my regular computer win - xp Sp 2 that I utilize for school, and would like to use the Ethernet to hook up my newly acquired E-45 Server at my house, in order to see if it works... (0 Replies)
Discussion started by: little bo
0 Replies

9. Shell Programming and Scripting

Transfer file from local unix server to remote server

want to remove this thread. thanks (2 Replies)
Discussion started by: indira
2 Replies

10. HP-UX

Transfer file from local unix server to remote server

want to remove the thread thanks (2 Replies)
Discussion started by: indira
2 Replies
Login or Register to Ask a Question