NAME

File::Slurp::Remote::SmartOpen - open files locally or remotely automatially

SYNOPSIS

use File::Slurp::Remote::SmartOpen;

smartopen($file, $fd, $mode);

DESCRIPTION

This module provides one function, which is exported by default.

FUNCTIONS

smartopen($file, $fd, $mode)

Opens $file and puts the filehandle in $fd.

The function looks at the filename. As with scp, if it has a colon before any slash, then what comes before that colon is taken to be a hostname, and the rest (which may itself contain colons) is the path. If that hostname is not the hostname of the local system, it uses ssh to get to the remote system to open the file.

As with scp, the hostname may be given as user@host to log in to the remote system as a different user. Like ssh, the user name ends at the last @, so user@domain@host logs in to host as user@domain. The user name is passed to ssh with -l. If a user is given and it differs from the user running the program, ssh is used even if the host is the local system.

If the filename ends with .gz or .bz2, then it will pipe the input (or output) though zcat or bzcat (gzip or bzip2) as it opens the file.

The mode can be r or w. It defaults to read.

By default, remote files are accessed with

ssh -o StrictHostKeyChecking=no

You can override that by redefining $File::Slurp::Remote::SmartOpen::ssh.

RETURN VALUE

The process ID of the pipe when the file is opened through ssh or a compression program, otherwise a true value.

ERRORS

smartopen dies if the file cannot be opened. It also dies if the user or host is empty, or begins with -, so that it can't be taken as an ssh option.

EXAMPLES

smartopen("host1:/etc/passwd", my $fd, "r");

smartopen("fred\@host1:/home/fred/notes.txt", my $fd, "w");

LICENSE

This package may be used and redistributed under the terms of either the Artistic 2.0 or LGPL 2.1 license.