Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Net::MirrorDir help

by sunnyfedora99 (Novice)
on Nov 16, 2011 at 13:09 UTC ( #938368=perlquestion: print w/replies, xml ) Need Help??
sunnyfedora99 has asked for the wisdom of the Perl Monks concerning the following question:

Howdy Perl Monks, I'm trying to use the Perl Module Net::MirrorDir to compare local and remote directories. But in some cases I have file names with spaces between them and i can't get it compare the dir's. Is it possible to do compare directories when there are file names with spaces between them? Here is what i've got now:

sub compare_dirs { my ($host, $login, $password, $dir, $rmt_dir) = @_; my $md = Net::MirrorDir->new( ftpserver => $host, user => $login, pass => $password, localdir => $dir, remotedir => $rmt_dir, debug => 0, # 1 for yes, 0 for no timeout => 60 # default 30 ); $md->Connect(); my ($ref_h_local_files, $ref_h_local_dirs) = $md->ReadLocalDir(); my ($ref_h_remote_files, $ref_h_remote_dirs) = $md->ReadRemoteDir( +); my $ref_a_local_files_not_in_remote = $md->LocalNotInRemote( $ref_h_local_files, $ref_h_remote_files ); my $ref_a_remote_files_not_in_local = $md->RemoteNotInLocal( $ref_h_local_files, $ref_h_remote_files ); #transfer remote files which are not on local system foreach my $new_remote_file_not_in_local (@{$ref_a_remote_files_no +t_in_local}) { #transfer the files from remote site to local print "$new_remote_file_not_in_local... \n"; } #transfer local files not on remote system foreach my $new_local_file_not_in_remote (@{$ref_a_local_files_not +_in_remote}) { #transfer files from local site to remote site print "$new_local_file_not_in_remote... \n"; } }

any help is appreciated. Cheers

Replies are listed 'Best First'.
Re: Net::MirrorDir help
by toolic (Bishop) on Nov 16, 2011 at 15:00 UTC
    Do you get more information if you enable debugging?
    debug => 1, # 1 for yes, 0 for no
    Poke around in the source code of the Net::MirrorDir module. It uses readdir which should handle filenames with spaces, but the following line looks suspicious:
    @info = split(/\s+/, $line);
    What you describe seems like a bug, which you can report.

      Setting Debug to 1 gives me the following output of the 'readdir'

      returnvalues from <dir(/dir3)> -rw-r----- 1 ftp ftp 420730 Nov 17 10:38 file with spac +e.pdf -rw-r----- 1 ftp ftp 956 Nov 16 16:33 mail.txt

      But when it shows the file which doesn't match it show the following:


      I've opened up a bug case, to get this issue fixed.

        A cursory glance at the module source reveals this gem:

        ... for my $line (@{$ra_lines}) { @info = split(/\s+/, $line); $name = $info[$#info]; ...

        So yes, filenames containing spaces are broken. A potential fix might be

        @info = split(/\s+/, $line, 9); # 9 columns in FTP output

        ... if one could be sure that each FTP server would return 9 columns of output. Another alternative could be to rely on the file date/time as a marker, or to try a fixed width parser for the ftp output, and checking that split /\s+/ always returns the same number of items.

        Here is a quote from the "Changes" file...
        0.14 Sat Feb 23 10:36:50 2008 - using the function "$self->{_connection}->dir($dir)" to the sea +rch of the directory the FTP-server should return the following format as response of +the LIST command: -r--r--r-- 1 ftpuser ftpusers 576 Feb 23 09:23 file.txt drwxrwxr-x 2 ftpuser ftpusers 512 Feb 21 13:54 Dir1 Directory- or filenames should not contain any white space. - add some tests
        It looks like the author was aware of the limitation.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://938368]
Approved by marto
Front-paged by toolic
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2017-07-20 17:49 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (311 votes). Check out past polls.