FTP - Advanced

Declaration

<AMFTP ACTIVITY="advanced" FTPCOMMAND="text (options)" PARAMETER="text" SENTDATAVARIABLE="text" RESULTVARIABLE="text" SESSION="text" />

Related Topics   

Description

Sends specific customized commands to an FTP server. For most transactions, use the standard FTP Upload/Download activities.

NOTE: An FTP session is required to run this activity. Use the FTP Logon activity to create a session.

Practical Usage

The standard FTP download and upload commands send predetermined command sequences to the server. FTP Advanced is useful when it is necessary to create or perform a customized sequence of commands. For example, this activity could be used to return a folder listing. This list could then be looped to "examine" each file (such as the date) before performing some other action for each individual file based on the result.

Advanced FTP can also be used to perform commands that are server specific and/or not supported by other AutoMate FTP activities such as "Move" (moves the file on the FTP Server without downloading it first).

Parameters

Connection

Property

Type

Required

Default

Markup

Description

Session

Text

Yes

FTPSession1

SESSION="SessionName"

Specifies the session name (created by a previous FTP Log on step) that this activity should originate from. This permits several FTP activities to be linked to a specific session, thus, allowing multiple simultaneous FTP transfers to take place within a single task.  

Advanced

Property

Type

Required

Default

Markup

Description

FTP command

Text

Yes

(Empty)

  1. FTPCOMMAND="connect"

  2. FTPCOMMAND="help"

  3. FTPCOMMAND="delete_file"

  4. FTPCOMMAND="connect"

Specifies the advanced command to execute. Click the down arrow and select the desired command from the drop-down list that appears. These advanced commands are described in the Advanced FTP Commands table below.

NOTE: The FTP command you need to execute may not be included in the list or you may be required to run a custom or server specific command. In such cases, you can select the User defined option from the drop-down list to define a custom command or select the Site command option to define a server or site specific command. Use the Parameter(s) section below to enter your custom or site specific command.

Parameter(s)

Text

No

(Empty)

  1. PARAMETER="c:\filename.txt"

  2. PARAMETER="*.txt"

  3. PARAMETER="Foldername"

Indicates required parameter(s) for the command specified. The use of parameters vary depending on the command selected and in certain cases may not be required. If you selected the User defined or Site command option from the drop-down list, enter any required parameters in this section.

Populate variable with sent data

Text

No

(Empty)

SENTDATAVARIABLE="variableName"

Specifies the name of an existing variable to be populated with information regarding the command or any data sent to the server.

Populate variable with return data

Text

No

(Empty)

RESULTVARIABLE="variableName"

Specifies the name of an existing variable to be populated with information regarding return data (depending on the command sent).

Create dataset with file listing information

Text

No

(Empty)

FTPLONGLISTDATASET="datasetname"

 

Specifies the name of the dataset to be populated with file listing information. Only available if the GetLongFileList command is selected, which retrieves all files that reside in the location specified and populates a dataset with the results. You can then loop through the dataset  and perform other actions on each file or determine whether or not to download the current file depending on the name, date, size, etc. More on the exclusive column names that this dataset creates are detailed below under Datasets.

Advanced FTP Commands

The table below describes the available FTP commands found in the FTP Command drop-down list (displayed in alphabetical order for convenience). Data includes command name, compatible command line entry, general description and sample syntax (if applicable). Note that depending upon the version of FTP and the operating system being used, each of the below commands may or may not work. 

Command

DOS

Description

Sample Syntax (if applicable)

ASCII mode

TYPE A

Switches the mode of file transfer to ASCII. Often used when transferring text files with FTP servers that do not use ASCII as the base character set. One example is EBCDIC.

ASCII

Binary mode

TYPE I

Switches the mode of file transfer to binary. Normally used to transfer binary files or any file types other than ASCII.

NOTE: Binary should be used when transferring executable files. In binary mode, the file is moved byte-by-byte.

BINARY

Change folder

CWD

Changes the current working directory or folder to a new working directory or folder in the remote server.

"/ParentFolder/NewFolder"

Clear command channel mode

CCC

Reverts a secured control/command channel back to plaintext (unsecured). If the CCC command is enabled, the FTP client connects to the server, negotiates a secure connection, authenticates the user, then reverts back to plaintext.

NOTE:  SSL connections require CCC when connecting in PORT mode from behind a NAT firewall.

N/A

Create folder

MKD

Creates a folder or directory in the remote server.

MKD NewFolder

Delete file

DELE

Deletes a single file in the remote server.

"/Home/FileToDelete.txt"

Delete multiple files

MDELETE

Deletes one or more files in the remote server using a mask.

*.dat

Download file

GET

Downloads a single file (PORT followed by RETR).

"/RemoteFileName.exe/" [optional]\"C:\\LocalFileName.exe\"

Download multiple files

MGET

Downloads one or more remote files to the local computer

"/RemoteFolder/*.html"

File exists

---

Checks if a file exists in the remote server.

"/RemotePath/FileName"

Folder exists

---

Checks if a folder exists in the remote server.

"RemoteFolderPath"

Get file checksum

---

Gets the checksum of the remote file using a specific algorithm (CRC, MD5, SHA1).

N/A

Get long file list

LIST

Retrieves a remote server verbose file listing (PORT command followed by LIST).  

*.exe

Get short file list

NLST

Retrieves a basic file listing located in the remote server (PORT command followed by NLST command).

*.exe

Help

HELP

Displays FTP help information

N/A

Passive mode

PASV

Switches to passive mode to properly negotiate server connections through firewalls. In the passive mode, the client sends a PASV command to the server and then receives a server IP address and server port number, which the client then uses to open a data connection to the server IP address and server port number received.

N/A

Remove folder

RMD

Removes a folder in the remote server.  

\"Old Folder\"

Rename file

RNFR

Renames a file in the remote server (i.e., RNFR command followed by RNTO command).

"/Home/Folder/FileName.txt" "/Home/NewFolder/NewFileName.txt"

Retrieve current folder

PWD

Displays the current directory on the remote computer (literally, "print working directory")

"FolderName"

Site command

SITE

Sends site specific commands to remote server.

CHMOD or DIRSTYLE

System Information

SYST

Retrieves information about the remote server.

NOTE: Only supported in FTP with normal SSL/TLS connection types.

N/A

Up one folder

CDUP

Change to the parent folder

N/A

Upload file

PUT

Upload one file (PORT followed by STOR).

\"C:\\Local FileName.exe\" [optional]\"\Remote FileName.exe\"

Upload multiple files

MPUT

Upload one or more files (PORT followed by MPUT).

\"C:\\*.exe\" [optional]\"\RemoteFolder\"

Upload file

PUT

Upload one file (PORT followed by STOR).

\"C:\\Local FileName.exe\" [optional]\"/Remote FileName.exe\"

User defined

---

Issues a custom command to the FTP server.

N/A

 

Description

Error Causes

On Error

Additional Notes

Datasets

A dataset is a multiple column, multiple row container object. This activity creates and populates a dataset containing a specific set of fields in addition to the standard dataset fields. The table below describes these fields (assuming the dataset name assigned was theDataset).

 

Name

Data Type

Return Value

theDataset.FTPFileName

Text

The name of the current file.

theDataset.FTPFileSize

Number

The size of the current file.

theDataset.FTPFileDate

Date

The date of the current  file.

theDataset.FTPFileType

Boolean

Whether the current file type is a folder or file. If it is a folder, 0 is returned. If it is a file, 1 is returned.

Example

NOTE: The sample AML code below can be copied and pasted directly into the Steps panel of the Task Builder.

Description:

This sample task will demonstrate how AutoMate can delete files older than 30 days via FTP. The first step logs onto to an FTP server. Next, a "Get long file list" command using the FTP Advanced action populates a dataset with the file list results. A Loop Dataset action loops through the dataset that holds the list of files and folders on the FTP server. Within the loop block of steps, an If action is used specifying the %DateDiff()% function, which gets a day differential between today's date and the date of the file on the FTP server. If the file is older than 30 days, it is deleted. If not, it is skipped. The last step logs off the FTP server.

 In order for this task to work, please make appropriate modifications to the FTP logon credentials and other necessary properties for each activity.

<AMFTP ACTIVITY="logon" SERVER="YourFTPHost" USERNAME="YourUsername" PASSWORD="AM1NYGaQ+SuSz0MaN4SJbOlag==aME" SESSION="FtpSession1" />

<AMFTP ACTIVITY="advanced" FTPCOMMAND="long_list" PARAMETER="*.*" FTPLONGLISTDATASET="FileList" SESSION="FtpSession1" />

<AMLOOP ACTIVITY="dataset" DATASET="FileList">

   <AMIF EXPRESSION="%DateDiff(&quot;d&quot;, DateValue(FileList.FTPFileDate), Now())% &gt; 30">

      <AMFTP ACTIVITY="delete" SOURCE="%FileList.FTPFileName%" SESSION="FtpSession1" />

   </AMIF>

</AMLOOP>

<AMFTP ACTIVITY="logoff" SESSION="FtpSession1" />