Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Net::SFTP::Foreign getting files

by salva (Abbot)
on Apr 11, 2013 at 13:35 UTC ( #1028159=note: print w/replies, xml ) Need Help??

in reply to Net::SFTP::Foreign getting files

as $ai_dir is "", $ai_dir/${file} becomes /$file, so, it is trying to download the files from the file system root. Probably not what you want.

As a workaround, use setcwd to let the module compose paths for you.

Also, mget second argument must point to a directory.

$sftp->setcwd($ai_dir); $sftp->mget($file, $ai_dest_day) or $newerr=1;

Replies are listed 'Best First'.
Re^2: Net::SFTP::Foreign getting files
by kofs79 (Initiate) on Apr 11, 2013 at 14:01 UTC

    Thanks for pointing out the setcwd as it was something I missed. The system that is being connected to does have a jailed ftp directory so it does show as root but it could've been a problem in the future.

    I still get a number being assigned as the file name in the output. I had added some print statements to see what file names I was getting and I don't get anything. In the glob I had also tried names_only=>1

    Connected to Trying to login to Login was successful. 0 Failed to retreive file 0 : 1 Failed to retreive file 1 : 1 Failed to retreive file 1 : Failed to retreive file snapshot_20130410 :
      Oh, I see, you are calling glob in scalar context where it returns the number of files matching. Also, you don't need mget when you have already used glob to resolve the name. get will do in that case:
      ($file) = $sftp->glob($file, names_only => 1); defined $file or die "file not found"; $sftp->get($file, "$ai_dest_day/$file");

        Ok now I am getting the file names and downloading them the way I was hoping for with one exception. In my script I want a file "IRP_20130410" the remote server has a file named "IRP_20130410000438.txt" The remote windows machine adds 6 characters for time and the ".txt" extension. I want to be able to match the file name I am looking for and don't care about the remaining characters. So can I just put a wild card in the glob?

        ($file) = $sftp->glob("${file}*", names_only => 1); defined $file or die "file not found"; $sftp->get($file, "$ai_dest_day/$file");

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028159]
[holli]: And I kindly suggest you post a question, instead of spamming the chetterbox
[holli]: my spelling... can you actually aquire dyslexia?
[LanX]: SoPW = Seekers of Perl Wisdom, the section for asking and answering general Perl questions. A form for asking a new Perl question can be found at the bottom of that page. (Be sure to read Posting on PerlMonks before posting!)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2017-10-23 15:33 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (280 votes). Check out past polls.