sFTP File Transfer Wrapper
Categories
Component ID
2919483
Component name
sFTP File Transfer Wrapper
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Downloads
122
Component created
Component changed
Component body
Developers Only
This module will help you to hide all the complexity of Remote File Transfer operations by exposing upload/download methods and configuration page. You can create multiple connections to work with multiple sFTP servers. No need to worry about error handling, error messages would be saved to your watchdog table.
- Library supported:
- Phpseclib
- Protocol supported:
- sFTP
- Authentication supported:
- Password
- Private key (.ppk)
How to integrate in your project?
Below are the two Steps that you need to perform --
1. Configure connection settings by visiting this url -- http:///admin/config/file_transfer_connections
2. Now you need to call appropriate methods whenever required from your code as below --
try {
// This will create a connection to the specified remote file server. 'qa-portal' is the custom connection name that you need to add to the above configuration page to identify a particular remote file server. Also it will switch to the remote directory that is specified in the above configuration.
$classObj = ftwFtwConnectionFactory::build('qa-portal');
// Below are the methods that you can use as per your requirement.
// Create Directory with the name specified.
$classObj->createDirectory('test2');
// Download file based on the prefix defined on unless specified any argument.
$classObj->downloadFile(); // Or you can specify remote file name as below
$classObj->downloadFile('remotefile.txt');
// Upload a local file to the remote file server.
$classObj->uploadFile('example_1.txt');
}
catch(Exception $e) {
drupal_set_message($e->getMessage(), 'error');
}
This also provides Test link for each connection which performs remote file server connection test step by step as below --
- Create remote directory.
- Create file to the above created remote directory.
- Download above created file to the local directory as specified by the configuration.
- Recursively delete(all contents in this directory) remote directory.