Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a linux box (Debian) which is up 24/7. I'd like to set it up in such a way, that once a day it connects to a specific FTP server and checks if any files have changed since the last check. If they have, it should send me an email with a list of the changed files.

The check doesn't have to be thorough - I'll be happy if it just compares file dates. But it has to be recursive.

How can I do this? I understand I can use cron to schedule the process, but what do I use to connect and check for changes?

share|improve this question
up vote 1 down vote accepted

The ncftp client has the ncftpls tool which can do a recursive long list.

share|improve this answer
I'm looking at that too. Actually, I suppose this is what would solve the problem... if I had not solved it in another way. Still, this question is valid in itself. :) – Vilx- Jun 18 '09 at 11:17

Here is a Perl solution using Net::FTP. The below script should print the filename and timestamp for each file in the fileserver. You can easily extend this to suit your actual needs.


use strict;
use Net::FTP;
use File::Listing qw(parse_dir);
use POSIX qw(strftime);

# Configuration Options
my $FTP_SERVER        = 'ftp_host_name';
my $FTP_USER          = 'username';
my $FTP_PASS          = 'password';

# Establish FTP connection
my $ftp = Net::FTP->new( $FTP_SERVER, Debug => 0 )
  or die "Cannot connect to $FTP_SERVER: $@";
$ftp->login( $FTP_USER, $FTP_PASS )
  or die "Cannot login ", $ftp->message;

# Get list of files
my $files = $ftp->dir;
foreach my $entry (parse_dir($files)) {
    my ($fileName, $type, $size, $mtime, $mode) = @$entry;
    next unless $type eq 'f';
    my $timeStamp = strftime "%Y-%m-%d %H:%M:%S", gmtime($mtime);
    print "Name: $fileName\t Time Stamp: $timeStamp\n";

share|improve this answer

I'm pretty sure lftp can be scripted to do this; otherwise, I'd just use an FTP library for my favourite scripting language (Ruby/Perl/Python) and do the job that way.

share|improve this answer
I had an idea of [some FTP folder listing software here, ncftp perhaps?] -> diff -> grep (filters out a few folders I don't care about) -> email. – Vilx- Jun 18 '09 at 9:21

Here is a shell script to help you on your way. If you can execute this over ssh, then you're done. If you have to do it over FTP, then you'll be meeting my old friend Expect. Good luck!

#!/usr/bin/env bash

if [ ! -f .baseline ]; then
    echo "No timestamp available for comparison. Exiting."
    exit 1

for filename in ./*
    if [ .baseline -ot "$filename" ]; then
        echo "$filename"

touch .baseline

share|improve this answer

Use wget. First day:

wget -r -q --spider --no-remove-listing --ftp-user=YOU --ftp-password=YOURSECRET ftp://YOURSERVER   2>&1

This command will produce a local directory named YOURSERVER with a downloaded directory tree underneath, but each directory will contain only one file called ".listing". The .listing files can be compared to old copies with diff command.

Now each day:

wget as above

This will print all lines that differ, and cron should automatically mail the result to you.

share|improve this answer
Seems a step in the right direction! Would of course be nicer if there was just one file, not a whole tree. – Vilx- Jun 18 '09 at 9:44
Luckily diff -r compares nicely whole directory trees. I agree it would be better to have a FTP client supporting something like 'find . -ls' and store just one listing file locally. I am not sure why do you need the file names, but in case you want to download these files: wget has -N option (downloads newly modified/created files). – kubanczyk Jun 18 '09 at 10:07
I want to know what has changed, and then decide on my own whether these files a worthy of downloading and putting in a SVN folder. – Vilx- Jun 18 '09 at 10:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.