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

I'd like the option to ftp multiple files via ftp. What I have works for sending one file, but not 2+. How do I get the following to recognize the array @list and do the following for each element?
# foreach $file (@list) #{ $log = "log"; $command = <<eod; ftp -nv $rem_host << eof > $log; user $rem_user $rem_passwd put $file $ftp_dest_path bye eof eod system($command);
#}

Replies are listed 'Best First'.
Re: ftp multiple files
by suaveant (Parson) on Apr 16, 2001 at 21:20 UTC
    May I suggest using Net::FTP, it works very well and is well documented... then you could just run a put command in a for loop.
                    - Ant
      We don't have the Net::ftp module here.
        It is possible to install it as a user... but not necessarily easy...

        what about a program like ncftpput... it allows you to put a file in a single command, and I think it comes with a normal redhat installation (only helps if you are in redhat, of course)
                        - Ant

Re: ftp multiple files
by z0d (Hermit) on Apr 16, 2001 at 21:23 UTC
    Consider using Net::FTP. Your idea about that FTP transfer is a bit unsecure/uncool.

    <-- z0d -->
Re: ftp multiple files
by Beatnik (Parson) on Apr 16, 2001 at 23:03 UTC
    If you are indeed using a plain shell call over Net::FTP (as suggested above) you might as well use mput which allows filemasks... something like mput *.txt is ofcourse possible.
    Net::FTP doesn't appear to have mput (and mget), but you can loop a put statement : foreach $file (@files) { $ftp->put($file); }

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
      Do you get my reply to the other responses? I don't have the Net::ftp module; only you provided a non Net::ftp solution. I tried this and I get the following message:
      #!/usr/bin/perl @files = ($file1,$file2,$file3); print "Enter $rem_host login name\n"; $rem_user = <STDIN>; chop $rem_user; print "Enter password\n"; $rem_passwd = <STDIN>; chop $rem_passwd; $rem_host = machinename; $log = "log \n"; $command =<<eod; foreach $file (@files) { ftp->mput($file); } # ?? (where do i put this) ftp $rem_host << eof > $log; user $rem_user password $rem_passwd bye eof eod
      error: Can't call method "mput" on an undefined value at ./eod.pl... I also tried "put" - same error. Can you clarify what you mean about mput*.txt? Obviously, I'm not sure what you mean. Thanks!
        Put and Get dont appear to be in the FTP RFC... mput and mget are basically client side commands, check man pages on ftp

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