Hello

I'm trying to move files from one server to a new one, so I made a simple script using ftp, problem is Net::FTP broke files, here is my script:

#!/usr/bin/perl use strict; use warnings; use Cwd; use File::Spec; use Getopt::Long; use Net::FTP; use DBI; use Digest::MD5::File qw(-nofatals file_md5_hex); use File::Basename; my $path = File::Spec->catdir(getcwd()); my $host, my $username, my $password; GetOptions ( "dir=s" => \$path, "host=s" => \$host, "user=s" => \$username, "pass=s" => \$password ) or die("Error in command line arguments\n"); $path = File::Spec->catdir(getcwd(),$path); # Connect my $ftp = Net::FTP->new($host,Passive => 0) or die("Can't connect to: +$!"); $ftp->login($username,$password) or die("Couldn't authenticate ftp: $! +"); #$ftp->pasv(); $ftp->binary(); my $dbh = DBI->connect("DBI:SQLite:dbname=moving.db", "", "", { RaiseE +rror => 1 }) or die $DBI::errstr; $dbh->do(q{ CREATE TABLE IF NOT EXISTS "files"( hash TEXT, path TEXT, size INT )}); my @tree = ($path); loop: { $path = pop(@tree); opendir(DIR, $path) or die $!; unless ($ftp->cwd($path)) { $ftp->mkdir($path,1) or die "$! ", $ftp->message; $ftp->cwd($path) or die "$! ", $ftp->message; } while (my $file = readdir(DIR)) { next if $file =~ m/^\./ or ! $file; $file = File::Spec->catdir($path,$file); if (-d $file) { push @tree,$file; next; } $ftp->put($file) or die "$! ", $ftp->message; die(sprintf("$file didn't match size %s <> %s",$ftp->size( +$file),-s $file)) if $ftp->size($file) != -s $file; $dbh->do('INSERT INTO "files"(hash,path,size) VALUES (\''. +file_md5_hex($file).'\',\''.$dbh->quote($path).'\',\''.$dbh->quote(-s + $path).'\')') or die $DBI::errstr; print "Moved: $path\n"; } closedir(DIR); if (scalar @tree) { goto loop; } } $ftp->quit;

When its send a file it add some extra space, even with binary mode, both OS are the same Ubuntu 12.04, do you have an idea what could be wrong? because I'm a bit lost

Thanks


In reply to Net::FTP bug or is my error? 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.