The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Transfer file from local unix server to remote server indira Shell Programming and Scripting 2 05-03-2007 06:35 AM
Transfer file from local unix server to remote server indira HP-UX 2 05-02-2007 05:15 PM
How to check the file status in a remote server? rajus19 Shell Programming and Scripting 3 04-28-2006 04:45 AM
FTP a file to a remote Server shivaraj Shell Programming and Scripting 2 02-26-2006 03:29 AM
FTP - Get the file date and time on the remote server gthokala Shell Programming and Scripting 12 06-28-2005 08:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-26-2006
anujairaj anujairaj is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 13
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 (permalink)  
Old 09-26-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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 (permalink)  
Old 09-26-2006
anujairaj anujairaj is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 13
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 (permalink)  
Old 09-26-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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 (permalink)  
Old 09-27-2006
anujairaj anujairaj is offline
Registered User
  
 

Join Date: Apr 2006
Posts: 13
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 (permalink)  
Old 09-27-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0