Name
Connector::Proxy::Net::FTP
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 21.
- file
-
Pattern for Template Toolkit to build the filename. The connector path components are available in the key ARGS. In set mode the unfiltered data is also available in key DATA. For security reasons, only word, space, dash, underscore and dot are allowed in the filename. If you want to include a directory, add the path parameter instead!
- path
-
Same as file, but allows the directory seperator (slash and backslash) in the resulting filename. Use this for the full path including the filename as the file parameter is not used, when path is set!
- 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
-
FTP username
- password
-
FTP password
- timeout
-
FTP connection timeout, default is 30 seconds
- debug (Boolean)
-
Set the debug flag for Net::FTP
- active (Boolean)
-
Use FTP active transfer. The default is to use passive transfer mode.
- binary (Boolean)
-
Use binary or ascii transfer mode. Note that binary is the default!
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::FTP->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 scp 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.