On linux you can use the dnotify mechanism, for example using this program. Interesting enough there doesn't seem to be a direct perl module for it, though it shouldn't be very hard to do.

update A later node teaches me that there is a perl module: SGI::FAM also works on linux. It needs you to have the fam library installed though.

update Here is some pure perl code interfacing to linux dnotify. Unfortunately there seems to be no way to get to the siginfo data. This example watches directory /tmp, but you can also watch an (existing) file. You'd probably do the real detecting of what changed not in the signal handler but after the pause(). I used a realtime signal to allow for signal queueing, but since you can't get to the siginfo information anyways (to get the fd on which there was a change), it probably makes sense to leave the signal on e.g. SIGIO, and just rescan all places you are watching.

#!/usr/bin/perl -w use strict; use POSIX qw(pause sigaction SA_SIGINFO); use constant { DN_ACCESS => 0x00000001, DN_MODIFY => 0x00000002, DN_CREATE => 0x00000004, DN_DELETE => 0x00000008, DN_RENAME => 0x00000010, DN_ATTRIB => 0x00000020, DN_MULTISHOT=> 0x80000000, F_SETSIG => 10, F_LINUX_SPECIFIC_BASE => 1024, SIGRTMIN => 32, SIGRTMAX => 64, }; use constant F_NOTIFY => F_LINUX_SPECIFIC_BASE+2; my $signum = SIGRTMIN+1; my $dir = "/tmp"; my $new_action = POSIX::SigAction->new(sub { print STDERR "Change in $dir"}); $new_action->safe(1); sigaction($signum, $new_action) || die "Could not sigaction signal $signum: $!"; open(my $fh, "<", "/tmp") || die "Could not open $dir: $!"; fcntl($fh, F_SETSIG, $signum) || die "Could not set IO signal to $signum for $dir: $!"; fcntl($fh, F_NOTIFY, DN_MODIFY|DN_CREATE|DN_DELETE|DN_MULTISHOT) || die "Could not set F_NOTIFY for $dir: $!"; pause while 1;
After each change you can now try to detect to see if a new upload has finished. However, you'll need to keep this process running and probably will be doing multiple checks while the file is still in the process of being uploaded. So in the end it's not clear that you gained much over not using dnotify at all and just periodically check for a finished upload.

In reply to Re: auto detection of file upload on ftp server by thospel
in thread auto detection of file upload on ftp server by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.