Perl FTP Recursive Binary Issue

Another day….. Today’s kick in the nether regions was using Net::FTP::Recursive ¬†which was defaulting to ascii transfer mode when doing a bulk website transfer. The issue was not with the text (html type) files but with the images. I believe then problem was in transferring the data from a Windows web server t a FreeBSD Apache web server. In ascii mode the system changes line ending as it sees fit, however the binary mode just moves the data ‘as is’. It wasn’t immediately obvious how to change the transfer mode of the Net::FTP::Recursive object and a search of Google didn’t do much either. Here is what we did in the end:

#! /usr/bin/perl -w

use strict;
use Net::FTP::Recursive;

my $ftp = Net::FTP::Recursive->new("", Debug => 0)
      or die "Cannot connect to $@";

# there is a load of code not relevant to the post

      or die "Cannot login ", $ftp->message;


So the line $ftp->binary(); was the key and all images fixed!

This entry was posted in FreeBSD Administration, Perl and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *