Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Net SFTP Foreign rget

by SpaansBolletje (Initiate)
on Nov 27, 2013 at 08:55 UTC ( #1064582=perlquestion: print w/replies, xml ) Need Help??
SpaansBolletje has asked for the wisdom of the Perl Monks concerning the following question:

I am using SFTP Foreign, for a script that I am making (Collect logging data from yesterday using a sFTP connection).

Since the package is new to me, I like to work in blocks, get the basic function working and then add more options. So first up was getting the log data and not worry about the date yet.

As the documentation says is that I need to use the rget (recursive get). I thought this would copy the folders inside the folder including the data.

What it does now, it copies only the directory names (in correct structure). So where did my files go?

As this is a offline machine, I am still looking how to get the debug prompt back to a usb stick.

I just read the debug log, and it notifies that the " remote files " are not regular files, directory or link. What does this mean? As it mostly is just log files in .log etc..

$host =; # Random ip for example $user = user; $pass = pass; $logcopy = /temp/sftp/01; $logpaste = copy01; ## Open connection my $sftp = Net::SFTP::Foreign->new($host, user => $user, password => $ +pass) or print "\nCould not open connection \n" . $sftp->error; ## Recursive get files $sftp->rget($logcopy, $logpaste) or print "Failed retrieving file. \n" + . $sftp->error;

Replies are listed 'Best First'.
Re: Net SFTP Foreign rget
by salva (Abbot) on Nov 27, 2013 at 09:04 UTC
    So, what do you get when you add $Net::SFTP::Foreign::debug=(~(8|16|1024|2048)) at the beginning of your script?

    Do you known which OS and SSH server is running on the remote side?

    Also, Net::SFTP::Foreign->new(...) returns always a true value. In order to check for errors, you have to call the error method afterwards (or the die_on_error shortcut) or alternatively use the autodie mode. In example:

    my $sftp = Net::SFTP::Foreign->new(...); $sftp->die_on_error("Unable to connect to remote host");
    or ...
    my $sftp = Net::SFTP::Foreign->new(..., autodie => 1);
      It is running windows xp, and hosting a sftp server. When i check the debug log, i see that the files are not regular files? They are just text files or xml files.

      set_error: _set_err code: 35, str: remote file '/temp/sftp/01/01.txt' is not regular file, directory or link

      And thanks for the error tip!
        In order to discover vendor and version of the software use telnet to connect to the ssh port on the server and it will tell you. For instance, this is what I get from my workstation:
        $ telnet localhost 22 Trying ::1... Connected to localhost.localdomain. Escape character is '^]'. SSH-2.0-OpenSSH_6.2p2 Ubuntu-6ubuntu0.1

        Also, can you dump the result of calling stat on any of those files that fail to transfer:

        use Data::Dumper; Print Dumper($sftp->stat('/temp/sftp/01/01.txt'));
      I have created my own recursive function. So I have a working solution. Thanks
        Could you provide the information I have requested on my previous posts anyway so that I can fix any bug present on the rget method, please?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1064582]
Approved by salva
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2018-07-23 00:32 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (458 votes). Check out past polls.