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

Hello monks, first off thank you for this website and your help. I am not a programmer/coder by any means, I am a sys admin. I am trying to write a script which will connect to an SFTP site and download certain files to a certain local directory. I have had some success but I am missing the last part. I can't seem to download to a directory, must a file name be specified? the problem is this script will run daily, and the file name changes daily (accounting purposes). Here is the code:
use Net::SFTP::Foreign; $host = "x.x.x.x" ; %args = ( "user" => "user" , "password" => "password" , "port" => 'port' ) ; my $sftp = Net::SFTP::Foreign->new( $host,%args, more => '-v'); $sftp->get('/directory/*.bai', '/home/appltest/cashman') or die "file transfer failed: " . $sftp->error;
I have read that sftp foreign does not accept wild cards such as "*" is this true? If so how would I go about solving my dilemma of downloading files which name changes daily. Thank you for your time.

Replies are listed 'Best First'.
Re: Net::SFTP::Foreign download to a local directory
by salva (Canon) on Jun 10, 2010 at 17:06 UTC
    Use the method mget:
    $sftp->mget('/directory/*.bai', '/home/appltest/cashman') or die "file transfer failed: " . $sftp->error;
      Beautiful, this worked perfectly! Thank you once again.
Re: Net::SFTP::Foreign download to a local directory
by almut (Canon) on Jun 10, 2010 at 16:46 UTC
    ... If so how would I go about solving my dillema of downloading files which name changes daily.

    Do a directory listing on the remote server.  See Download file from sftp or FTP

    Update: aha, looks like salva added the mget method in v1.56_07, in response to the the linked thread...