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

i am novice to per and not sure why i am not able to copy the *.log files from the server.
use Net::FTP; $ftp = Net::FTP->new("6.1.4.9", Debug => 0) or die "Cannot connect to 6.1.4.9: $@"; $ftp->login("login",'pwd') or die "Cannot login ", $ftp->message; $remote = "lps"; print $ftp->pwd (); $ftp->cwd($remote) or die "Cannot change working directory ", $ftp->message; $ftp->put("*.log") or die "put failed ", $ftp->message; $ftp->quit;
i need to copy to a directory in under lps.

Replies are listed 'Best First'.
Re: An FTP question
by roboticus (Chancellor) on Apr 20, 2007 at 11:08 UTC
    DV:

    From perldoc Net::FTP:

    put ( LOCAL_FILE , REMOTE_FILE )
    Put a file on the remote server. "LOCAL_FILE" may be a name or a filehandle. If "LOCAL_FILE" is a filehandle then "REMOTE_FILE" must be specified. If "REMOTE_FILE" is not specified then the file will be stored in the current directory with the same leafname as "LOCAL_FILE". Returns "REMOTE_FILE", or the generated remote filename if "REMOTE_FILE" is not given.
    You'll have to do the expansion yourself. When I get to work later, I'll put up some code that I use to get multiple files. Basically, you use the ls or equivalent method to get the list of filenames, then grep to get the list that match your regex, and then successively get the matches.

    ...roboticus

        But what roboticus meant could be the ls() method, which is supported by Net::FTP.
        Update: fixed worng poster name.

        Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Re: An FTP question
by naikonta (Curate) on Apr 20, 2007 at 10:49 UTC
    The notation *.log is for the shell to expand files matching the wild character. One of the perl ways is <*.log>, but then I'm not sure if put() accepts multiple files argument. So, assuming it can takes multiple files, you would do this,
    $ftp->put(<*.log>) or die "... message ...";

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Re: An FTP question
by Krambambuli (Curate) on Apr 20, 2007 at 10:52 UTC
    Is it possible that you just use an incorrect command, 'put' instead of 'get' ?

    You mention you wish to copy the .log file _from_ the server - but put() copies _to_ the server ?
      Hi it is put. i have mentioned it wrongly. But copy the *.logs is not happening