The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Name

Connector::Proxy::Net::SFTP

Description

Read/Write files to/from a remote host using FTP.

LOCATION is the only mandatory parameter, if neither file nor path is set, the file is constructed from the arguments given to the method call.

Parameters

LOCATION

The DNS name or IP of the target host.

port

Port number (Integer), default is 22.

basedir

A basedir which is always prepended to the path.

content

Pattern for Template Toolkit to build the content. The data is passed "as is". If data is a scalar, it is wrapped into a hash using DATA as key.

username

SFTP username

password

SFTP password

timeout

SFTP connection timeout, default is 30 seconds

debug (Boolean)

Set the debug flag for Net::SFTP

ssh_args

HashRef holding additional arguments to pass to underlying object. @see Net::SFTP / Net::SSH::Perl

Supported Methods

set

Write data to a file.

    $conn->set('filename', { NAME => 'John Doe', 'ROLE' => 'Administrator' });

See the file parameter how to control the filename.

get

Fetch data from a file. See the file parameter how to control the filename.

    my $data = $conn->set('filename');

get_keys

    Return the file names in the given directory.

Example

    my $conn = Connector::Proxy::Net::SFTP->new({
       LOCATION => 'localhost',
       file => '[% ARGS.0 %].txt',
       basedir => '/var/data/',
       content => ' Hello [% NAME %]',
    });

    $conn->set('test', { NAME => 'John Doe' });

Results in a file /var/data/test.txt with the content Hello John Doe.

A note on security

To enable the transfer, the file is created on the local disk using tempdir/tempfile. The directory is created with permissions only for the current user, so no other user than root and yourself is able to see the content. The tempfile is cleaned up immediatly, the directory is handled by the internal garbage collection.