in reply to Short example using IPC::Open2 or IPC::Open3

If you really want to interact with the sftp cli, I think Expect is nearly always a better choice than IPC::Open2 or IPC::Open3. That being said, however, there is an sftp option that can make this a lot easier with just backticks...

open( OUT, ">/tmp/sftp-batch" ); print OUT <<"END"; cd foo ls END close( OUT ); chomp( my @files = `sftp -b /tmp/sftp-batch hostname` ); open(OUT, ">/tmp/sftp-batch-2" ); print OUT <<"END"; cd foo lcd bar END for my $file ( @files ) { print OUT "get $file\n"; } system( "sftp -b /tmp/sftp-batch-2 hostname" );

We're not surrounded, we're in a target-rich environment!