Latest file through SFTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Latest file through SFTP
# 8  
Old 03-26-2010
MDTM can help you here
# 9  
Old 03-26-2010
Sorry, I didn't get whts MDTM means.
Can you please provide more description?
# 10  
Old 03-26-2010
You can't ssh, because they are probably using an SFTP jail which only allows sftp connections not shell ssh.

I'll try to brainstorm, but you may have ot downlaod all the files and hten do your processing locally then run another get. THat being said, that would mean you would have to download them all every time which if they are large could be a problem.

Is it possibly for you to do that?
# 11  
Old 03-26-2010
Code:
#!/bin/ksh
sftp host >filelist <<EOF
cd /u
ls -lt
quit
EOF

Will put an ls -l of remote /u in your current directory.
When I tried this is I was prompted for a password after I had typed EOF.

Last edited by jgt; 03-26-2010 at 10:05 AM.. Reason: typos
# 12  
Old 03-26-2010
Quote:
Originally Posted by jgt
Code:
#!/bin/ksh
sftp host >filelist <<EOF
cd /u
ls -lt
quit
EOF

Will put an ls -l of remote /u in your current directory.
When I tried this is I was prompted for a password after I had typed EOF.
Ah yes, good call on that didn't think about just outputing it to a file and then you can sort your list from there and extract only those you don't have. Now, how to do that is beyond my scripting abilities, but I'm interested in the answer.
# 13  
Old 03-26-2010
while using sftp, we can only use ls -l, So the files recived to local server will not be in publish time order.

Also, where this filelist file will get generated. on local drive / remote server ?

I executed the above script but do not see any file got created with file information.

---------- Post updated at 07:56 PM ---------- Previous update was at 07:32 PM ----------

I can see the file filelist generated on local drive.
After that, I included the below code to get the latest files

Code:
###TO display the files generated in March month.

latest_file=`cat filelist | grep Mar | awk '{print $6,$7,$8,$9}'`

echo $latest_file

##To get the latest files from the above list using timestamp file.

getList=`find $latest_file -type f -newer timestamp.check 
-name "ABC*"`

echo $getList

But still I am getting the file Timestamp.check can not found which is available on my local drive.
# 14  
Old 03-26-2010
Quote:
Originally Posted by ssachins
while using sftp, we can only use ls -l, So the files recived to local server will not be in publish time order.

Also, where this filelist file will get generated. on local drive / remote server ?

I executed the above script but do not see any file got created with file information.

---------- Post updated at 07:56 PM ---------- Previous update was at 07:32 PM ----------

I can see the file filelist generated on local drive.
After that, I included the below code to get the latest files

Code:
###TO display the files generated in March month.

latest_file=`cat filelist | grep Mar | awk '{print $6,$7,$8,$9}'`

echo $latest_file

##To get the latest files from the above list using timestamp file.

getList=`find $latest_file -type f -newer timestamp.check 
-name "ABC*"`

echo $getList

But still I am getting the file Timestamp.check can not found which is available on my local drive.
Is the timestamp.check in the same directory that you are running these commands from? If not, make sure you put the full path.

Also, I don't think you can run find on the variable value of $latest_file. Y0u will probably need to find another command to extract the data.

Like getting the line, extracting the date value and comparing it to date -d "-15 minutes"

Last edited by markdjones82; 03-26-2010 at 11:44 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Retrieve the Latest file in a folder using SFTP

HI Guys, Can anyone help me to retrieve the latest file from below example using SFTP I have below list of files in a folder v403t.lstprgms.sortin1 val027.d099.fwest.oct2711 xcelrptd.d1400sqp.dec1713.t040459.@02del xcelrptd.d1400sqp.dec1713.t073308.@02del... (3 Replies)
Discussion started by: heye18
3 Replies

2. Shell Programming and Scripting

Picking the latest file based on a timestamp for a Dynamic file name

Hi , I did the initial search but could not find what I was expecting for. 15606Always_9999999997_20160418.xml 15606Always_9999999998_20160418.xml 15606Always_9999999999_20160418.xml 9819Always_99999999900_20160418.xml 9819Always_99999999911_20160418.xmlAbove is the list of files I... (4 Replies)
Discussion started by: chillblue
4 Replies

3. Shell Programming and Scripting

Need to automate sftp and always get the latest file

hi guys the script is working but i need to change the file that i want to get to the latest.. i will use this as cron so i can get the latest sftp file evryday. pls help.. set user "big_user" set IP "XX.XX.XX" set dir "/export/home/oracle/REF/INPUT" spawn sftp $user@$IP expect sftp> ... (7 Replies)
Discussion started by: JONATHAN0919
7 Replies

4. Shell Programming and Scripting

Shell script to get the latest file from the file list and move

Hi, Anybody help me to write a Shell Script Get the latest file from the file list based on created and then move to the target directory. Tried with the following script: got error. A=$(ls -1dt $(find "cveit/local_ftp/reflash-parts" -type f -daystart -mtime -$dateoffset) | head... (2 Replies)
Discussion started by: saravan_an
2 Replies

5. UNIX for Dummies Questions & Answers

Find the latest file on remote sftp

Hi All, I need your help in finding the latest files in remote sftp and get those files to local server and process them. Please let me know I appreciate your valuable inputs. Thanks raj (7 Replies)
Discussion started by: rajeevm
7 Replies

6. Shell Programming and Scripting

Need to copy latest file using SFTP

Hi All, In my unix server, I have the following files: h1.txt h2.txt h3.txt and through SFTP i need to copy only the latest file to another unix server. Can you please let me know what command i need to use. Thanks in Advance, (2 Replies)
Discussion started by: HemaV
2 Replies

7. Shell Programming and Scripting

SFTP latest file from Windows server to Unix host

Hi All, I am SFTP ing file from Windows server (Sydney) to Unix host in London (both servers are on different timezones). It appears the upstream (Windows server team) does not do a file housekeeping activity and henceforth there are multiple files i.e. each week the script is scheduled to run... (1 Reply)
Discussion started by: vigdmab
1 Replies

8. Shell Programming and Scripting

get latest file

i have the following in my directory x: 3 files with the word "LIST" inside the files 2 files without the word "LIST" 1 folder (sudirectory) i want to get the filename of the latest file (timestamp) with the word "LIST". by the way the script and the list of files are in seperate... (4 Replies)
Discussion started by: inquirer
4 Replies

9. Shell Programming and Scripting

how to get the latest file

I am trying to scp the latest file which ends with "_abc.log". Can some help me figure out how can do that? (3 Replies)
Discussion started by: shehzad_m
3 Replies

10. Shell Programming and Scripting

How do I get the name of latest file?

1) How do I get the name of latest file in a variable? 2) Is it safe to delete all files from a dir I am doing cd $dir_name if return_code > 0 rm * fi what are other alternates to delete all files from a dir in a shell script? :) (5 Replies)
Discussion started by: Hangman2
5 Replies
Login or Register to Ask a Question