- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Delete files from FTP
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2003 02:35 PM
01-16-2003 02:35 PM
Delete files from FTP
only if they are 15 days old ?
{
echo "open $SERVER
user $USER $PASS
ascii
cd temp
-- delete 15 days old files ?
close"
} | ftp -i -n
thnx in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2003 02:47 PM
01-16-2003 02:47 PM
Re: Delete files from FTP
I don't think you have any commands in the ftp server to list the files older than 15 days. What you might get away with is something like this:
open your connection and login
get a list of all the files
closing the connection
If you redirect the output from this session to a file, you can write a script to figure out which files you want to delete and build a script to drive a second ftp session to login and delete the files.
open connection and login
delete file
delete file
...
close
I don't know what your situation is, but it probably would be much easier to delete the old files from the ftp server end.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2003 06:12 PM
01-16-2003 06:12 PM
Re: Delete files from FTP
You can not search for files older from ftp prompt. The best and easiest way would be to search and delete them from the ftp server side by putting some scripts and then triger the ftp from there instead from your end.
Thanks
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2003 06:21 PM
01-16-2003 06:21 PM
Re: Delete files from FTP
Just as an object lesson to you guys that say it can't be done and as another opportunity to bang you over the head with "USE PERL FOR FTP", I whipped this example up in under 5 minutes. As is, it logs in, cd's to /tmp, does an ls, and gets the last modification times of each file. If any are older than 15 days, it deletes them.
You will need to install the Net::FTP module from www.perl.org/CPAN. You will also need to uncomment the actual delete call when you get close.
Some suggested improvement:
1) Do a dir and only look for regular files but that is left as an exercise for the reader. 2) Add a bit of error checking - hard with scripts but duck soup with Net::FTP.
That's all you get for 5 minutes.
Smug regards,
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2003 06:23 PM
01-16-2003 06:23 PM
Re: Delete files from FTP
You can do it with quite a bit of scripting if you really want to do.
You may have to do it in multiple iterations
Your first part will get the details. This is a high level script.
#!/usr/bin
{
echo "open $SERVER
user $USER $PASS
ascii
cd temp
dir
close"
} | ftp -i -n > ftp.log
tough_part()
{
This ftp.log contains output with files and their date stamps. Here is the most difficult part. Find out the files in the output that are more than 15days (how?). Try caljd.sh floating around in these forums. Assign them to a variable say FILES.
Use ftp again to delete them using "mdelete"
}
{
echo "open $SERVER
user $USER $PASS
ascii
cd temp
mdelete $FILES
close"
} | ftp -i -n
Since it is tedious, I would suggest you to run a script through cron on the ftp server to clean the files.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2003 07:03 PM
01-16-2003 07:03 PM
Re: Delete files from FTP
I didn't say it couldn't be done. My point was that it could be done with some scripting.
the humble JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2003 07:39 PM
01-16-2003 07:39 PM
Re: Delete files from FTP
I trust that you know that was all tongue in cheek. This was simply an irrestible chance to illustrate what is at best tedious using shell, awk, grep, cut, ... becomes almost trivial when you choose the right club.
Humble (more or less) regards, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2003 08:14 AM
01-17-2003 08:14 AM
Re: Delete files from FTP
No problem. I was a little miffed when I first read it but I quickly got over it. It was late and I was tired. No offense taken. Besides, you were right. :)
I don't mind people being smug when they really, really know what they are doing! Please feel free to keep banging my hard head with good solutions. The owner's manual that came with me states, "Repeated percussive maintenance to the cranial region eventually yields positive results." ;)
the still humble JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2003 09:01 AM
01-17-2003 09:01 AM
Re: Delete files from FTP
Try to this via a remote shell instead!
remsh
If your remote system isn't a remsh incompatible environment try via ftp by "literal" command.
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2003 12:20 PM
01-17-2003 12:20 PM
Re: Delete files from FTP
Next we check to see if the file has been modified in the last 15 days. If not the file is deleted.
With only a little more work, you could make this a recursive function that would descend directories and continue the process but that is left as an exercise.
The power of this approach is that it could even be run from a Windows box without change. I never do any FTP stuff with Perl anymore; it's just too hard any other way especially if you care about minor little things like error checking.