1 ftp
<ftp
debug='debug'
host='host'
port='port'
user='user'
password='password'
passive='passive'
bufferSize='bufferSize'
connectTimeout='connectTimeout'
defaultTimeout='defaultTimeout'
dataTimeout='dataTimeout'
soTimeout='soTimeout'
keepAliveTimeout='keepAliveTimeout'
controlKeepAliveReplyTimeout='controlKeepAliveReplyTimeout'
config-setSystemType='config-setSystemType'
config-setServerLanguageCode='config-setServerLanguageCode'
config-setDefaultDateFormat='config-setDefaultDateFormat'
config-setRecentDateFormatSrt='config-setRecentDateFormatSrt'
config-setServerTimeZoneId='config-setServerTimeZoneId'
/>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Adebug | boolean | false | Performs a debug on the ftp communication. | ||
Ahost | String | Name of domain or IP address of the FTP server. | |||
Aport | number | 21 | Port of access, if not indicated port 21 is used. | ||
Auser | String | Valid username to login. | |||
Apassword | String | Associated password. | |||
Apassive | boolean | false | The communication with the server is done in passive mode. | ||
AbufferSize | number | Establishes the size of the intern buffer. | |||
AconnectTimeout | number | Establishes the waiting time in seconds to perform the connection with the server. | |||
AdefaultTimeout | number | Establishes the waiting time in seconds to perform file transfer operations between the client and the server. | |||
AdataTimeout | number | Establishes the waiting time in seconds during the data reading. | |||
AsoTimeout | number | Establishes the waiting time in seconds of the currently open connection. | |||
AkeepAliveTimeout | number | Time in seconds that defines how often a NOOP command is sent to keep the connection alive. During the file transfer, the data connection is busy, but the control connection is inactive. The FTP servers should know that the control connection is being used, so that they do not close the connection due to lack of activity. | |||
AcontrolKeepAliveReplyTimeout | number | Establishes the waiting time for the connection control message responses. | |||
Aconfig-setSystemType | String | UNIX | Establishes the server's operating system. | ||
Aconfig-setServerLanguageCode | String | Establishes de code ISO-639 of the language. | |||
Aconfig-setDefaultDateFormat | String | Establish the default format with which you want to display the timestamp of the files. | |||
Aconfig-setRecentDateFormatSrt | String | Establishes the format with which you want to visualize the timestamp of the files with less than one year old. | |||
Aconfig-setServerTimeZoneId | String | Establishes the time zone of the server. |
Exceptions
attribute 'host' required
The IP address of the FTP server has not been specified.
attribute 'user' required
An username has not been indicated.
attribute 'password' required
A password has not been specified.
ftp already in use, close it first
It is not possible to establish a FTP communication with the server because there is one in progress (for the same user and host).
no active ftp connection
It is not possible to get the FTP communication with the server because there is not established.
java.net.SocketException: Connection reset
It is not possible to establish a connection with the indicated host.
Remarks
This file transfers are performed between the application server on which the script is executed and another remote FTP server. The function <ftp> offers the functionality of a client FTP application. The different methods returns codes as specified by the FTP protocol. See details in: https://en.wikipedia.org/wiki/List_of_FTP_server_return_codes
Ver tambien
Class FtpClient: swig.stanford.edu/pub/java/javadoc/sun/net/ftp/FtpClient.html
RFC 959 - File Transfer Protocol: www.ietf.org/rfc/rfc959.txt
List the content of the home directory, upload an image and list again the names of the files contained in the directory.
<xsql-script name='ftp_sample1'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftpdeister'> <println><ftp.list /></println> <ftp.put name='imagen_subida.jpg'> <file name="/tmp/nevada.jpg" type="absolute" /> </ftp.put> <println><ftp.nlst /></println> </ftp> </body> </xsql-script>
In the communication of the example, it is ordered to list the contents of the default folder that is accessed when logging in, using the function <ftp.list>. The list is visualized by screen with the print label <println>, appearing the following information:
drwxrwxrwx 2 ftpuser ftpuser 4096 Feb 20 04:00 clients -rw-r--r-- 1 ftpuser ftpuser 3321363 Feb 8 09:43 jt400.jar -rwxr--r-- 1 ftpuser ftpuser 19 Feb 25 11:43 null_test.xml drwxr-xr-x 3 ftpuser ftpuser 4096 Mar 17 2004 pub -rw-r--r-- 1 ftpuser ftpuser 102400 Dec 31 11:03 solaris.tar -rwxr--r-- 1 ftpuser ftpuser 111083130 Jan 29 17:39 t5.zip -rw-r--r-- 1 ftpuser ftpuser 386 Feb 25 09:24 text drwxr-xr-x 2 ftpuser ftpuser 4096 Feb 4 10:32 tmp
The second operation performed in the example is an upload of the snowfall.jpg file with the function <ftp.put>. This file is renamed to upload_image.jpg using the attribute name:
<ftp.put name='upload_image.jpg' /><file.open name='p:\snowfall.jpg' /></ftp.put>
Finally, a list is obtained again but in this time only with the file names of the remote folder <ftp.nlst>. The result would be:
pub solaris.tar t5.zip tmp text clients jt400.jar null_test.xml upload_image.jpg
Where upload_image is the file that was just transferred (from Application Server to the remote FTP server).
List the files of the FTP server that accomplish a condition and show an alert if any of them is a folder.
<xsql-script name='ftp_sample1'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftppasswd'> <set name='m_list'><ftp.listFiles pattern='*2012*' /></set> <iterator name='m_fileobj' index='i'> <in><m_list/></in> <do> <println><ftp.file.getName><m_fileobj/><ftp.file.getName/> <if> <expr><ftp.file.isDirectory><m_fileobj/></ftp.file.isDirectory></expr> <then> <println>Es Directorio</println> </then> </if> </do> </iterator> </ftp> </body> </xsql-script>
Download a file of the FTP server, storing it in a database.
<xsql-script name='ftp_sample2'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftpdeister'> <insert table='files' columns='image'> <value><ftp.get name='snowfall.jpg' /></value> </insert> </ftp> </body> </xsql-script>
To download file you should use the function <ftp.get>. An application of this function will consist in being able to download files of a remote server to storew them in a database. Starting out from this premise, the XSQL-Script is being executed in an application server, a download of the image snowfall.jpg from FTP server with the address 192.168.10.1 is made and it is inserted in the image column of the table files of the database indicated in the command ws-dbscript. The column must be defined with the data type BLOB (Binary Large OBject).
Print by screen the file of the working directory.
<xsql-script name='ftp_nlst_sample1'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftpdeister'> <println><ftp.nlst /></println> </ftp> </body> </xsql-script>
The name of the files contained in the home directory, shown by console, would be the following:
tmp cameras clients
Download a file.
<xsql-script name='ftp_get_sample1'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftpdeister'> <ftp.get name='snowfall.jpg' /> </ftp> </body> </xsql-script>
Change the name of the file.
<xsql-script name='ftp_rename_sample1'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftpdeister'> <println><ftp.nlst /></println> <println><ftp.rename src='camaras' dst='videos' /></println> <println><ftp.nlst /></println> </ftp> </body> </xsql-script>
The file called 'cameras' is renamed to 'videos'.
Check that exist the indicated file in the home directory.
<xsql-script name='ftp_exists_sample1'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftpdeister'> <println><ftp.exists name='clients' /></println> </ftp> </body> </xsql-script>
The name of the files contained in the home directory, shown by console, would be the following:
tmp camaras clientes
Print by screen the content of the working directory.
<xsql-script name='ftp_list_sample1'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftpdeister'> <println><ftp.list /></println> </ftp> </body> </xsql-script>
The content of the folder home directory visualized by console, would be the following:
drwxr-xr-x 2 ftpuser ftpuser 225280 Sep 6 06:37 cameras drwxr-xr-x 3 ftpuser ftpuser 4096 Aug 30 11:06 clients drwx------ 2 (?) vsalvador 4096 Jun 27 16:50 tmp
<xsql-script name='ftp_cdup_sample1'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftpdeister'> <println><ftp.list /></println> <ftp.cwd dir='clients' /> <println><ftp.list /></println> <ftp.cdup /> <println><ftp.list /></println> </ftp> </body> </xsql-script>
Completing the example of the tag <cwd>, you change the work directory 'clients' to the parent directory, which is '/', going up one level in the hierarchy.
List the content of the home directory, access to a subdirectory and list the content of this directory.
<xsql-script name='ftp_cwd_sample1'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftpdeister'> <println><ftp.list /></println> <ftp.cwd dir='clients' /> <println><ftp.list /></println> </ftp> </body> </xsql-script>
The execution of the script shows the right functioning of the directory change tag. First, it visualizes by the console the content of the home directory, access to the directory specified in the attribute dir ('clients') and finally, lists again the content of the new work directory.
Print by screen the name of the work directory.
<xsql-script name='ftp_pwd_sample1'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftpdeister'> <println><ftp.pwd /></println> </ftp> </body> </xsql-script>
The name of the directory visualized in the console would be:
/
Print by screen the name of the operative system of the remote host.
<xsql-script name='ftp_system_sample1'> <body> <ftp host='192.168.10.1' user='ftpuser' password='ftpdeister'> <println><ftp.system /></println> </ftp> </body> </xsql-script>
The result by screen would be:
UNIX Type: L8
Shows by screen a resultset with the content of a remote directory.
<xsql-script name='listFilesAsResultSet_sample1'> <body> <ftp host='remotehost' user='userftp' password='passftp' config-setServerTimeZoneId='CEST'> <ftp.cwd dir='REP/DEL03' /> <set name='m_dirpattern'><string>2013*</string></set> <!-- Without raw --> <println> <ftp.listFilesAsResultSet pattern='#m_dirpattern'/> </println> <!-- With raw --> <println> <ftp.listFilesAsResultSet pattern='#m_dirpattern' raw='true'/> </println> </ftp> </body> </xsql-script>
The result by screen would be:
+--------------+------+------+----+----+---------------------+----+ |name |group |user |type|size|date |raw | |char |char |char |char|long|datetime |char| +--------------+------+------+----+----+---------------------+----+ |20130108223447|user |user |D |4096|02-05-2013 10:06:00 | | |20130109224001|user |user |D |4096|02-05-2013 10:06:00 | | +--------------+------+------+----+----+---------------------+----+ +--------------+------+------+----+----+---------------------+---------------------------------------------------------------------+ |name |group |user |type|size|date |raw | |char |char |char |char|long|datetime |char | +--------------+------+------+----+----+---------------------+---------------------------------------------------------------------+ |20130108223447|user |user |D |4096|02-05-2013 10:06:00 |drwxrwxr-x 2 user user 4096 May 2 08:06 20130108223447| |20130109224001|user |user |D |4096|02-05-2013 10:06:00 |drwxrwxr-x 2 user user 4096 May 2 08:06 20130109224001| +--------------+------+------+----+----+---------------------+---------------------------------------------------------------------+