Delete files older than 1 year through FTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete files older than 1 year through FTP
# 1  
Old 06-26-2012
Delete files older than 1 year through FTP

Hi All,

I want to login to a remote server using FTP command and then check for files older than 1 year and delete those files.
Please let me know how can i achieve this using Unix Commands.

Thanks in Advance,
# 2  
Old 06-26-2012
Please mention the exact Operating System and version of both computers and the Shell used on both computers.

Though not impossible, it is extremely difficult to achieve this with ftp alone. Unix ftp is not unix Shell and it has a very limited command set.

Do you have administrative access to the remote computer? Do you have Remote Shell access to the remote computer?
I see from your previous posts two month ago that you use ftp a lot, but never managed to work out what Operating System or Shell you had.
# 3  
Old 06-26-2012
Both the servers are unix servers with AIX uname. I'm using Korn Shell.

Is this the information required? if not how to find out.

Thanks in Advance,
# 4  
Old 06-26-2012
If both servers are AIX, surely you can use Remote Shell or a cron or whatever. Anything but ftp. In fact the file transfers would be easier with Remote Copy.
The only real use for ftp nowadays is to copy files between incompatible systems.
# 5  
Old 06-26-2012
You can redirect the "dir" in one ftp session to a log, parse the log and get the list of files you want to delete. Then delete them in another ftp session.
# 6  
Old 06-26-2012
Or you could use Perl with Net:FTP (core module since v5.7.3).

Remove all files that are 365 days old:
Code:
perl -MNet::FTP -e'
    ( $host, $user, $pass ) = @ARGV;
    $ftp = Net::FTP->new($host) or die "$@\n";
    $ftp->login( $user, $pass ) or die $ftp->message;
    $ftp->mdtm($_) < time - (86400 * 365) and $ftp->delete($_) for $ftp->ls; 
    $ftp->quit or die $ftp->message;
    ' <host> <user> <pass>

Standard disclaimer: you should backup your data before running the above code! You may need to add a file name filter, change the working directory etc.
# 7  
Old 06-26-2012
@binlib
Please post your AIX-compatible code to determine if a file is more than a year old based on a ftp directory listing.

My technique is to create dummy files on the source system with a timestamp deduced from the ftp directory listing, and then use the unix "find" command to determine which files to delete from the destination server.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Delete all files created in specific year

I have more than 200K files created in year 2017 under directory having size of 50GB. I want to all these files in one shot. Is there any faster option available with find command to delete all these file ? (6 Replies)
Discussion started by: sp23029
6 Replies

2. Shell Programming and Scripting

Deleting dated log files whihc are older than an year

Hi. There is a process which creates log files in the below naming format processname.20140425.log processname1.20140425.log And in this path along with these logs there are other files which have the timestamp from 2012 and i want to have a script in place to delete only the above log files... (13 Replies)
Discussion started by: nanz143
13 Replies

3. Shell Programming and Scripting

Delete files using year

Hi All, how can i delete files from my Unix directory on the basis of year, i have files from 2001 to till 2014, but from their, i have to delete only 2013 file.Below is my file name rwxrwxrwx 1 guopt users 5169 Jul 12 00:30 grt592_20130712003000.SAP Thanks Kki (2 Replies)
Discussion started by: kki
2 Replies

4. Shell Programming and Scripting

Delete all the files and subdirectories for the year 2006

Hi I have lot of files and subdirectories inside a directory which are created in the years 2006, 2007, 2008, 2009 and 2010. I want to delete all the files and subdirectories belonging to the year 2006 alone. How can I do that ? (5 Replies)
Discussion started by: samsungsamsung
5 Replies

5. Shell Programming and Scripting

To delete files older than 24 hrs

I have to retain only 1 day files in my system an I have to delete all the other files which are older than 24 hrs. Please let me know the option I have to give in the find -mtime command. (3 Replies)
Discussion started by: rajesh8s
3 Replies

6. UNIX for Dummies Questions & Answers

Delete files by year

can someone provide a command to delete files by year? I have several files created last year 2009. Im trying to list first ls -lrt | grep '/2009/ {print $10}' by it returns no result. Pls advise (2 Replies)
Discussion started by: lhareigh890
2 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. UNIX for Dummies Questions & Answers

Reg: delete older files from ftp

Hi, I want to delete older files from ftp server. (files which are more than 5 days old). Please advice Thanks , sam (3 Replies)
Discussion started by: sam99
3 Replies

9. UNIX for Dummies Questions & Answers

delete compressed files from year 2005

I'm trying to delete files that were created/modified in the year 2005 that we compressed and have the .Z extension on them. I tried using the awk utility but the syntax is incorrect. I don't know how to use a wildcard to capture all the compressed files. Here's the code I used ( ls -lR |... (5 Replies)
Discussion started by: igidttam
5 Replies
Login or Register to Ask a Question