When i try to upload certain template files using my ancient CMS (Bricolage) virtual FTP, they fail to transfer and give the error "wide character in print". I have dealt with this forever and want to try to tackle it if anyone can help sleuth. There is no chance the dev is going to fix this abandonware.
It seems to be a bug with net::FTPServer which has not been updated in over a decade.
Seems it's probably not expecting uft8 characters? Can anyone see from the spot that causes the error, if there would be a way to work around it by patching this file:
Here is the exact spot:
Here's an excerpt from that with the last line being the one that throws the error
while ($r = $file->sysread ($buffer, 65536))
{
$self->xfer ($r) if $self->{_xferlog};
# Restart alarm clock timer.
alarm $self->{_idle_timeout};
if ($transfer_hook
= $self->transfer_hook ("r", $file, $sock, \$buffer))
{
close $sock;
$file->close;
$self->_cleanup_filters (@filter_objects);
$self->reply (426,
"File retrieval error: $transfer_hook",
"Data connection has been closed.");
return;
}
for ($n = 0; $n < $r; )
{
# $w = $sock->syswrite ($buffer, $r - $n, $n);
$w = syswrite $sock, $buffer, $r - $n, $n;
Net::FTPServer::__ANON__("Wide character in syswrite at /usr/lib64/perl5/site_perl/5.10"...) called at /usr/lib64/perl5/site_perl/5.10.1/Net/FTPServer.pm line 5448
"Wide character in print" is not an error, it's a warning. Using diagnostics will tell you more:
Wide character in print at ... (#1) (S utf8) Perl met a wide character (>255) when it wasn't expecting one. This warning is by default on for I/O (like print). The easiest way to quiet this warning is simply to add the :utf8 layer to the output, e.g. binmode STDOUT, ':utf8'. Another way to turn off the warning is to add no warnings 'utf8'; but that is often closer to cheating. In general, you are supposed to explicitly mark the filehandle with an encoding, see open and "binmode" in perlfunc.
Another way how to fix the problem is to encode the string.
use Encode qw{ encode };
print "\N{GREEK CAPITAL LETTER OMEGA}"; # This warns.
print encode('UTF-8', "\N{GREEK CAPITAL LETTER OMEGA}"); # This doesn't.