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

I know I'm being redundant, but why doesn't this work?
$log = "log"; if ($list == 1)# one file to send { blah (this part works); } elsif ($list == 2) # multiple files to send { foreach $file (@initList) { $command = <<eod; ftp -nv $rem_host << eof > $log; user $rem_user $rem_passwd mput $ftp_source_path[$i] $ftp_dest_path[$i] bye eof eod } }
I think there's something wrong with my put notation but I don't know how to fix it. This loop won't even update the log file. argh.

Replies are listed 'Best First'.
Re: ftp multiple files revisited
by davorg (Chancellor) on Apr 18, 2001 at 20:31 UTC

    You're not setting $i anywhere that I can see. You might be better off with something like this:

    foreach $i (0 .. $#initList) { $command = <<eod; ftp -nv $rem_host << eof > $log; user $rem_user $rem_passwd mput $ftp_source_path[$i] $ftp_dest_path[$i] bye eof eod }

    But I really think you'd be better of using Net::FTP.

Re: ftp multiple files revisited
by traveler (Parson) on Apr 18, 2001 at 21:09 UTC
    Ahhh, you are using mput. mput requires a confirmation for each action unless you turn that off. Add prompt y on a line by itself before the mput. Since you are using mput for single files, though, why not use put? Also, have you considered opening $rem_host only once and then sending put lines for each file?

    BTW, not all ftp clients allow command line input as you are using. I assume yours does because single files work, but on *nix you could also use ncftpput which allows some more control from the command line.

    --traveler

      I get the error: Not connected. Not connected. With or without prompt y, with put or mput. But only for multiple files loop. It doesn't make any sense. Is someone willing to look at more of the program, it's a real messy thing I inherited that I don't want to subject to this site! Thanks.
Re: ftp multiple files revisited
by Masem (Monsignor) on Apr 18, 2001 at 20:58 UTC
    Well, you set $command to a bunch of FTP commands, but do nothing with it. You need to send this to the system or whatever other mechanism that you are using to communicate with the OS to get the commands to run.
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
Re: ftp multiple files revisited
by zigster (Hermit) on Apr 18, 2001 at 20:33 UTC
    IIRC put does not take two args, you need to do a cd to $ftp_dest_path($i) first. However I would suggest you look at net::ftp as it will make your life in such code soooo much easier. Have a look on Super search there are lots of nodes showing how to use it.

      put does take two arguments, the source and destination filesnames. Both can also include paths.

      --
      <http://www.dave.org.uk>

      "Perl makes the fun jobs fun
      and the boring jobs bearable" - me

        Second one is optional...

        put local-file [remote-file]

        mput takes only local filenames...

        mput local-files

        Greetz
        Beatnik
        ... Quidquid perl dictum sit, altum viditur.