Establish a SFTP communication (Secure File Transfer Protocol).
1 sftp
<sftp
host='host'
port='port'
user='user'
password='password'
debug='debug'
>
<sftp.pwd /> *
<sftp.list /> *
<sftp.put /> *
<sftp.get /> *
<sftp.exists /> *
<sftp.rename /> *
<sftp.delete /> *
<sftp.mkdir /> *
<sftp.listFiles /> *
<sftp.file.getName /> *
<sftp.file.getSize /> *
<sftp.file.isDirectory /> *
<sftp.file.getTimestamp /> *
<sftp.listFilesAsResultSet /> *
<sftp.cwd /> *
<sftp.getBytes /> *
</sftp>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Ahost | String | Name of domain or IP address of the SFTP server. | |||
Aport | int | 22 | Port of the SFTP server. | ||
Auser | String | Username valid to start session. | |||
Apassword | String | Password associated. | |||
Adebug | boolean | false | true to activate the debug mode. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Esftp.pwd | Shows the working directory in the remote host. | ||||
Esftp.list | Shows the content of the working directory (in the remote host). | ||||
Esftp.put | Load a file (to the remote hash). | ||||
Esftp.get | Download a file (of the remote host). | ||||
Esftp.exists | Check the existence of a directory (in the remote host). | ||||
Esftp.rename | Rename a file (in the remote host). | ||||
Esftp.delete | Remove a file (in the remote host). | ||||
Esftp.mkdir | Create a directory (in the remote host). | ||||
Esftp.listFiles | Returns the collection of files of the working directory (in the remote host). | ||||
Esftp.file.getName | Obtains the name of the file passed as argument (of the collection sftp.listFiles). | ||||
Esftp.file.getSize | Obtains the size of the file passed as argument (of the collection sftp.listFiles). | ||||
Esftp.file.isDirectory | Returns true when the file passed as argument (of the collection sftp.listFiles) is a directory. | ||||
Esftp.file.getTimestamp | Obtains the date and time of the last modification of the file passed as argument (of the collection sftp.listFiles). | ||||
Esftp.listFilesAsResultSet | Returns a ResultSet of the files of the working directory (in the remote host). | ||||
Esftp.cwd | Changes the working directory.. | ||||
Esftp.getBytes | Read directly a file sftp and returns the read bytes. |
Example
Before execute the following example, the corresponding host, user, password and file names should be specified.
Copy
<xsql-script> <body> <sftp host='host' user='xxx' password='yyyy'> <println>PWD : <sftp.pwd /></println> <println>LIST : <sftp.list /></println> <println>PUT : test.dat -> test-remote1.dat</println> <sftp.put name='test-remote1.dat'> <file name='test.dat' type='absolute' /> </sftp.put> <sftp.get name='test-remote1.dat' localname='test-from-remote.dat' /> <println>LIST : <sftp.list /></println> <println>EXISTS: test-remote1.dat:<sftp.exists name='test-remote1.dat' /></println> <println>RENAME: test-remote1.dat -> test-remote2.dat</println> <sftp.rename src='test-remote1.dat' dst='test-remote2.dat'/> <println>EXISTS: test-remote1.dat:<sftp.exists name='test-remote1.dat' /></println> <println>EXISTS: test-remote2.dat:<sftp.exists name='test-remote2.dat' /></println> <println>DELETE: test-remote2.dat</println> <sftp.delete name='test-remote2.dat' /> <println>EXISTS: test-remote2.dat:<sftp.exists name='test-remote2.dat' /></println> <if> <expr> <sftp.exists name='test' /> </expr> <then> <println>EXISTS: dir test</println> </then> <else> <sftp.mkdir name='test' /> </else> </if> <println>LIST-F: <sftp.listFiles /></println> <iterator name='file'> <in> <sftp.listFiles /> </in> <do> <println><sftp.file.getName><file /></sftp.file.getName></println> <println><sftp.file.getSize><file /></sftp.file.getSize></println> <println><sftp.file.isDirectory><file /></sftp.file.isDirectory></println> <println><sftp.file.getTimestamp><file /></sftp.file.getTimestamp></println> </do> </iterator> <println>LIST-F: <sftp.listFilesAsResultSet /></println> <println>LIST-F: <sftp.listFilesAsResultSet raw='true' /></println> </sftp> </body> </xsql-script>