Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Net::FTP and filenames with spaces

by amelinda (Friar)
on Feb 12, 2002 at 19:08 UTC ( #144952=perlquestion: print w/replies, xml ) Need Help??

amelinda has asked for the wisdom of the Perl Monks concerning the following question:

So, I just went and upgraded to a newer libnet in the hopes that it would handle filenames with spaces better. (As per Spaces in file names with Net::FTP) Unfortunately, I couldn't find any examples which showed -how- people made the newer Net::FTP work with spaces in filenames. Of course, I'm trying to build the filenames on the fly (with timestamps), instead of just a 'string filename'.
My current code is as follows:

my @type = ('farm\ &\ ranch', 'land', 'residential'); my $server = 'not.the.real.server.net'; my $c = Net::FTP->new($server); $c->login('username', 'password') or die "couldn't log in: $!\n"; for my $i (0..2) { $c->get("listings-$type[$i].txt.gz"); for my $j (0..6) { my $k = timestamp($j); $c->get("pics-$type[$i]-$k.tar"); } } $c->quit(); exit; sub timestamp() { my $days = shift @_; my @today = localtime(time - (86400 * $days)); $today[4]++; $today[5] += 1900; return sprintf("%04d%02d%02d", @today[5,4,3]); }

I'm sure that this could be written more tightly. I'm far more interested in 'working' than 'tight' right now, since this needs to be working before I leave for a week this evening.

I have verified that I am connected to the server, am logged in correctly, and can download the other files that don't have spaces in them. Someone's got to know... please help.

Replies are listed 'Best First'.
Re: Net::FTP and filenames with spaces
by jlongino (Parson) on Feb 12, 2002 at 19:42 UTC
    You didn't say what version of libnet you're using. My versions:
    This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 regist +ered patch, see perl -V for more detail) Copyright 1987-2001, Larry Wall Binary build 628 provided by ActiveState Tool Corp. http://www.ActiveS +tate.com Built 15:41:05 Jul 4 2001 libnet [1.07.03] Collection of Network protocol modules
    The following program works for me:
    use strict; use Net::FTP; my $host = 'mysite.net'; my $login = 'mylogin'; my $passwd = 'mypasswd'; my $ftp = Net::FTP->new($host); my $RC = $ftp->login($login, $passwd); if (not $RC) { print "\n\nFTP Login to Remote Host: '$host' failed!\n\n"; print "No files updated from Remote host: '$host'!\n\n"; exit; } ### Delete local copy of remote host ftp files my $infile = "test" . ' ' . "file"; ### also the following works too # my $infile = "test file"; if (-e $infile) { unlink $infile; } ### Make new local copy of remote host ftp files $RC = $ftp->get($infile); if (not $RC) { print "\n\nget command for remote file: '$infile' failed!\n"; print "No files updated from Remote host: '$host'.\n\n"; exit; } $ftp->quit; print "Finished!";
    I know you said that you just want to get it working, but you should really consider basic error/return code checking as I've done above. Maybe there are additional problems.

    --Jim

      Welp, I had just installed libnet 1.0901, perl 5.002 (yes, I know it's out of date... no upgrade on it currently possible). This is on a MacOS X machine, fwiw.

      I also forgot to mention that I had cut out the error checking I had been doing, for the sake of posting a smaller amount of code. I am doing error checking. Thanks for mentioning it tho.

        After seeing your libnet version (1.0901) I rechecked ActiveState and found that the same (newer than mine) version was available. Thanks, I at least like to keep the modules up-to-date too! I probably should check the rest of my modules for updates too.

        --Jim

Re: Net::FTP and filenames with spaces
by amelinda (Friar) on Feb 12, 2002 at 19:44 UTC
    :grumble:

    replacing 'farm\ &\ ranch' with 'farm & ranch', which I could have sworn last night didn't work, today did work.

    Hopefully someday this node will be of use to some other poor sod trying to deal with idiots who like spaces in filenames.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://144952]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2020-11-28 08:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?