Syntax

SETPASSIVE(mode)

  • mode:
    ENABLED Default. Enable passive transfer mode.
    DISABLED Disable passive transfer mode. This mode is called Active in the FTP standard.

Return value:

This command always returns “OK”.

Remarks:

Passive is used by default. Should you experience firewall problems please read this section carefully. Switching the transfer mode and/or configuring your firewall may help.

This command only works with FTP and FTPS protocols as “passive mode” is a concept related to these protocols only. SFTP protocol works in a completely different way to transfer file data.

When connecting to an FTP server the client usually opens port 21 on the server where the server is listening and waiting for incoming connections. You may change your FTP server configuration such that it listens on a different port, however, port 21 is the standard. Once the connection has been established the client will authenticate to the server and then this connection is the one client and server will use to ‘chat’ with each other. For file transfers this connection will not be used, rather a new connection will be established for each file in order to transport the file’s data. There are two methods for opening these new data channels: Active and Passive. The purpose of the SETPASSIVE command is to select the method that ScriptFTP will use. By default ScriptFTP uses passive mode.

  • Active Mode:

    In Active mode (also called non passive) the client starts listening on port N+1 and sends the FTP command PORT N+1 to the FTP server. The server will then connect back to this data port of the client using its own local data port, which is port 20. The file’s data will then be transferred using this connection.

    From the client’s perspective the following communication channels need to be allowed in its own firewall in order to support active mode FTP:

    • Allow the connections to the port 21 of the server address (Client initiates connection).
    • Client’s port > 1024 from the server address (Server connects to the client’s data port to transfer a file).

    From the server’s perspective the following communication channels need to be allowed in its own firewall in order to support active mode FTP:

    • FTP server’s port 21 from anywhere (Client initiates connection)
    • FTP server’s port 21 to ports > 1024 (Server responds to client’s control port)
    • FTP server’s port 20 to ports > 1024 (Server initiates data connection to client’s data port)
    • FTP server’s port 20 from ports > 1024 (Client sends ACKs to server’s data port)

    In order to avoid the server having to initiate the connection to the client a different method for FTP connections was developed. This is known as Passive mode and it is the mode that ScriptFTP uses by default.

    In Passive mode the FTP client initiates the connection to the server, thereby solving the problem that a firewall has to filter the incoming connection from the server to the client’s data port.

  • Passive mode:
    The client will issue the PASV command whenever file data needs to be transferred. As a result the server will open a random unprivileged port (P > 1024) and send a PORT P command back to the client. The client will then initiate the connection to port number P on the server in order to transfer the file data.From the client’s perspective the following communication channels need to be allowed in its own firewall in order to support active mode FTP:

    • Allow the connections to the port 21 of the server address (Client initiates connection).
    • Allow the connections to ports > 1024 of the server address (Client connects to the server’s data port to transfer a file).

    From the server’s perspective the following communication channels need to be opened in its own firewall in order to support passive mode FTP:

    • FTP server’s port 21 from anywhere (Client initiates connection)
    • FTP server’s port 21 to ports > 1024 (Server responds to client’s control port)
    • FTP server’s ports > 1024 from anywhere (Client initiates data connection to random port specified by server)
    • FTP server’s ports > 1024 to remote ports > 1024 (Server sends ACKs (and data) to client’s data port)

See also:

GETFILE
PUTFILE
SYNC

Examples:

# Connect to ftp.myhost.com, download sales.xls
# using active mode and upload it
# to a local server using passive mode
 
# The file is downloaded to the Windows temp directory
LOCALCHDIR("C:\WINDOWS\TEMP")
 
OPENHOST("ftp.myhost.com","myuser","mypassword")
# Use active transfer mode
SETPASSIVE(DISABLED)
GETFILE("sales.xls")
CLOSEHOST
OPENHOST("192.168.1.53")
# Go back to passive mode
SETPASSIVE(ENABLED)
PUTFILE("sales.xls")
CLOSEHOST
 
# Delete sales.xls
EXEC("del sales.xls")