Help with get/mget from FTP server with files older than 10 minutes


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Help with get/mget from FTP server with files older than 10 minutes
# 1  
Old 12-17-2012
Help with get/mget from FTP server with files older than 10 minutes

Hi! I am new to unix and this forum as well..
Can someone please help me :

I want to "get/mget" files which are older than 10 minutes from a remote FTP server like "ftp.com".
After getting the files to local unix server say "Prod.com" , i need to delete only those files from ftp.com which got copied to local unix server.

The files in the FTP server (ftp.com) will be coming in below format:

Code:
FileName FileSize FileType Last Modified

abc.pkg 102,272 PKG File 12/17/2012 2:46:00 PM
xyz.pkg 98,546 PKG File 12/17/2012 1:46:00 PM
mno.pkg 14,656 PKG File 12/17/2012 1:05:00 PM


Last edited by Franklin52; 12-18-2012 at 04:16 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 12-17-2012
Check your find command manual and verify if it supports -mmin option. If yes, then you can use find, ssh & sftp to perform file transfer:-

1. Create an SFTP batch file using ssh (ssh-key needs to be configured):-
Code:
ssh ftp.com "find -mmin +10 | sed 's/\.\///g'" | awk ' { print "get " $0 } ' > sftp_batch.cntrl

2. Run the SFTP batch file using sftp (ssh-key needs to be configured):-
Code:
sftp -b sftp_batch.cntrl ftp.com

# 3  
Old 12-17-2012
No, sftp is not supported for us Smilie

I have my code like this:
Code:
 cmdINPUT=$tempdir/ftpinput
 rm -f $cmdINPUT
 echo "user $FTPID $FTPPWD " > $cmdINPUT
 echo "pwd "                                    >> $cmdINPUT
 echo "cd xxx"              >> $cmdINPUT
 echo "mget *.pkg"                      >> $cmdINPUT
 echo "cd xxx/Backup "    >> $cmdINPUT
 echo "mput *.pkg"                             >> $cmdINPUT
 echo "cd .. "                                  >> $cmdINPUT
 echo "mdelete *.pkg"                  >> $cmdINPUT
 echo "bye "                                    >> $cmdINPUT
 echo "quit"                                    >> $cmdINPUT
 echo "Connecting to $remotehost"  >> $log 
 ftp -vdni $remotehost < $cmdINPUT >> $downloadlog 2>$downloaderrorlog

how to change it to get/mget only files older than 10 minutes from remote host (ftp.com) and also delete only those files from remote host after copying.

Last edited by Franklin52; 12-18-2012 at 04:16 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 12-17-2012
Please always use code tags when posting any code fragments or data samples. If you are not sure how to use code tags, then please have a look at this forum video tutorial

BTW I don't think there is any way to do this inside FTP. You have to generate the list of files older than 10 minutes outside FTP and use it.
# 5  
Old 12-17-2012
Yes, thats what i was looking for. If someone can help me with it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

Hello all, Info: System RedHat 7.5 I need to create a script that based on the creation time, if the file is older then 5 minutes then execute some stuff, if not exit. I thought to get the creation time and minutes like this. CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Discussion started by: charli1
3 Replies

2. UNIX for Dummies Questions & Answers

FTP mget will only grab files not folders

Hey All, first post :rolleyes: So I am writting a script to pull down files from an ftp that will be called from a bat file on windows. This seems pretty straight forward, and grabs all of the "files" in the cd location, but I am running into some permission issue that will not allow me to... (1 Reply)
Discussion started by: mpatton
1 Replies

3. Shell Programming and Scripting

Ftp get files created in last 30 minutes

Is it possible in an ftp script to get remote files based on whether they have been created in the last 30 minutes? (5 Replies)
Discussion started by: gefa
5 Replies

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

5. UNIX for Advanced & Expert Users

files older than 10 minutes

Hi, I have to find the files older than 10 minutes and remove those files as well as redirect the file names into a log file. i am using sun OS and my unix is not GNU and also not having perl. Could any one suggest me the way to approach. It would be great if script is provided. Also... (8 Replies)
Discussion started by: rohan10k
8 Replies

6. Shell Programming and Scripting

shell script - ftp downloading serveral files without mget

Hello guys, i'm searching for a solution how to download all files from root-directory of an ftp-server through an ftp proxy getting through the ftp proxy and download one file with get ist no problem, but mget * does nothing! ftp -n -i -v <<EOF open proxyHost proxyPort user... (19 Replies)
Discussion started by: macProgger23
19 Replies

7. Shell Programming and Scripting

ftp only older files

Hi All, I want to get those the files which were created before 20 days. Say, we have two server, remote server and local server. I want to get only 20 days older files from remote server to my local server. I have used following code for ftp: (echo " user ${USERNAME}... (2 Replies)
Discussion started by: priyankak
2 Replies

8. Shell Programming and Scripting

delete files older than 5 minutes in directory (recursively)

sorry guys can some please give me a hint how to achieve this in a slick oneliner? delete files older than 5 minutes in specified directory (recursively) peace (3 Replies)
Discussion started by: scarfake
3 Replies

9. Shell Programming and Scripting

only find files older than x minutes old

I am looking for a way to show files that have been created within a certain period (say anything older than 10 minutes or so). Is there a command/series of commands I can do this with? As an example, I have the following in a directory: -rw-r--r-- 1 owner group 70175 May 16 09:10... (1 Reply)
Discussion started by: dsimpg1
1 Replies

10. Shell Programming and Scripting

files older than 15 minutes

Hi Friends, i have to write a script to raise a flag if there are any files that are older than 15 minutes in the directory.The directory is supplied as the parameter to the script. please help with a sample script. Thanks in advance veera (0 Replies)
Discussion started by: sveera
0 Replies
Login or Register to Ask a Question