RSS Feeds for FTP Servers
by Mark Woodman
|
Pages: 1, 2, 3, 4
Put It to Work
After placing ftp_monitor.php on your PHP-enabled web server, you can reference it from any other PHP script. Here is an example of how that might look:
<?php
// Import the FTP Monitor
require_once('ftp_monitor.php');
// Connection params to monitor FreeBSD snapshots
$host = "ftp.freebsd.org";
$user = "anonymous";
$pass = "guest@anon.com";
$path = "/pub/FreeBSD/snapshots";
// Generate RSS 2.0 feed showing newest FreeBSD snapshots
generateRssFeed($host, $user, $pass, $path, 10);
?>
Here is a sample output file from the above connection parameters: freebsd.xml. When viewed in SharpReader, the items look like this:

Figure 2. FTP Monitor items for ftp.freebsd.org
Many RSS aggregators will automatically follow an item's link if it does not have a description element. SharpReader is one of these aggregators, and it also supports the ftp:// protocol. Thus, clicking on one of the items from our FTP monitor will start to download it automatically. This usually works just fine if the FTP server allows anonymous connections. If you had to provide a real username and password in ftp_monitor.php, however, your ability to "click and download" will depend on whether your RSS reader can prompt you for FTP credentials.
Enhance Your Performance
There are a few caveats to keep in mind when using this script. First, many FTP servers aren't exactly speedy, so the performance of this script will be bound by the response times of the FTP commands themselves. Simply put, the more directories it has to recurse, the longer it will take. Try to limit the scope of what you need to monitor.
Second, this script is not intended to be hit by a lot of concurrent users. The speed issue is one factor, but the other is FTP connections. For every concurrent hit to this script, a connection is made to the FTP server. It won't take much for the available connections to max out. So, if you want to provide an RSS feed to a lot of users, you should hide this script behind a cache which calls it on a periodic basis. Let the real load be handled by your cache, not the ftp_monitor script.
If you keep these constraints in mind, you can provide a nice service to your users which provides the information they need without frustrating response times.
Give It Back
If you find this script useful, or if you come up with a cool modification to it, I'd love to hear from you. Post a comment and share what you have learned with the xml.com community.
- doesn`t work for me
2006-12-15 16:20:23 Teresa3455 - weak reject
2006-03-31 20:14:21 olpa3 - setting the headers fails
2006-03-27 15:18:29 mariuss