0

I know this kind of question has been asked before, but I think I may have got lost trying to understand the examples provided in the responses. So I am asking it here again.

I have to collect list of files(absolute filenames only) from a particular folder on a remote machine.

On my Linux machine:

opendir - works locally. I want it to work remotely.

use Net::FTP - works but FTP disabled.

use Net::SFTP - could work but this Net::SFTP not installed.

I want some way to get this info considering that I have to make use of either sftp or ssh.

my $cmd = "ssh user\@host 'find x/y/z -type f'";
my @expectedOutputHere = system($cmd);

But $expectedOutputHere doesn't contain the list of files(as output). Once I have the output I am planning to use File::Basename::basename to get absolute names. But how do I first collect the output in an array?

2 Answers 2

4
my @expectedOutputHere = `$cmd`;

The manual says: The collected standard output of the command is returned, In list context, returns a list of lines.

For system(), the manual specifies: The return value is the exit status of the program.

Sign up to request clarification or add additional context in comments.

1 Comment

It's preferred to use the qx($cmd) syntax. It's easier to see than the back ticks, and allows a bit more flexibility in formatting.
1

Try this:

my $cmd = "ssh user\@host 'find x/y/z -type f'";
my @expectedOutputHere = `$cmd`;
chomp(@expectedOutputHere);
print Dumper @expectedOutputHere;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.