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

Okay, I installed Net::FTP and I have the following script, which *says* its sending the files but isn't. Why not?
% program.pl file1 file2
use Net::FTP; while (<>) { $ftp = Net::FTP->new("HOST", Debug => 0); $ftp->login("login",'passwd'); $ftp->put(*STDIN, $@); # here's the problem... } $ftp->quit;
Also, how do I put all the output of the ftp session into a log file?

Replies are listed 'Best First'.
Re: net::ftp multiple files
by RhetTbull (Curate) on May 10, 2001 at 01:09 UTC
    Try this. It works on my system.
    #!/usr/bin/perl use warnings; use Net::FTP; $ftp = Net::FTP->new("host", Debug => 1) || die "could not connect"; #qw(password) because my password has funky characters in it -- yours +should too ;-) $ftp->login("user",qw(password)) || die "could not login"; $ftp->cwd('./test') || die "could not cwd"; foreach (<@ARGV>) { $ftp->put($_) || die "could not put file $_"; } $ftp->quit;
    Setting Debug => 1 will dump the output of the FTP session -- that will probably help you figure out why it's failing. If it still doesn't work, post some Debug output and I'll take a look at it. Regards,

    RT

Check the home directory on the remote machine
by grinder (Bishop) on May 10, 2001 at 00:15 UTC

    Are you sure it's sending the files where you expect them to be sent? For instance, if you are sending the file /tmp/foo, that doesn't mean it will end up in /tmp/foo on the remote host. It'll get dumped in your home directory. You have to cd to the desired directory on the remote host before putting the file.

    As for the output from the session into a log file, I'm not sure what you mean. There is no output to log, apart from what you print out yourself to a log file. Otherwise if you're interested in what happens when you set Debug=>1 in the new method, then you should take a look at Net::Cmd (from which Net::FTP inherits).
    --
    g r i n d e r

      If no cwd is specified it should dump the files in the current directory. I added
      $ftp->cwd("/path");
      for clarity, and still, it says its successful but the files are not sent.
Re: net::ftp multiple files
by asiufy (Monk) on May 09, 2001 at 23:52 UTC
    Try this:
    #!/usr/bin/perl use Net::FTP; foreach (<@ARGV>) { $ftp = Net::FTP->new("HOST", Debug => 0); $ftp->login("login","password"); $ftp->put($_); } $ftp->quit;
    This will go thru the parameters given at the command line (like "./ftp.pl file1 file2 file3") and FTP them.
    I am not sure if any of the Net::FTP functions will return the output from the FTP server...
      This also says it's successful but the files do not appear on the remote machine.
Re: net::ftp multiple files
by no_slogan (Deacon) on May 09, 2001 at 23:54 UTC
    I'm confused about what you want to do with this code. Is it supposed to upload file1 and file2 to the server? Read a list of files to copy from file1 and file2? Copy its standard input to the server and store it as file1? What?
Re: net::ftp multiple files
by spaz (Pilgrim) on May 10, 2001 at 03:36 UTC
    As far as 'output of the ftp session' is concerned you can get this information from Net::FTP by setting Debug => 1 in your instantiation much as RhetTbull has.

    Using that on the command line will give you some really nice debugging info which will probably explain why your files aren't appearing

    -- Dave