FTPClient
FTPFileInfo
HTTPClient
HTTPClientLoggingConfig
HTTPRequestPart
Mail
SFTPClient
SFTPFileInfo
WebDAVClient
WebDAVFileInfo
DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!
Let us know so we can improve!
The FTPClient class supports the FTP commands CD, GET, PUT, DEL, MKDIR, RENAME, and LIST. The FTP connection is established using passive transfer mode (PASV). The transfer of files can be text or binary.
Note: when this class is used with sensitive data, be careful in persisting sensitive information to disk.
An example usage is as follows:
1var ftp : FTPClient = new dw.net.FTPClient();
2 ftp.connect("my.ftp-server.com", "username", "password");
3 var data : String = ftp.get("simple.txt");
4 ftp.disconnect();The default connection timeout depends on the script context timeout and will be set to a maximum of 30 seconds (default script context timeout is 10 seconds within storefront requests and 15 minutes within jobs).
IMPORTANT NOTE: Before you can make an outbound FTP connection, the FTP server IP address must be enabled for outbound traffic at the Commerce Cloud Digital firewall for your POD. Please file a support request to request a new firewall rule.
Deprecated:
The FTPClient is deprecated. Use SFTPClient for a secure alternative.
Warning
| Constant | Description |
|---|---|
The default size for get() returning a File is 5MB | |
The default size for get() returning a String is 2MB | |
| MAX_GET_FILE_SIZE: Number = 209715200 | The maximum size for get() returning a File is forty times the default size for getting a file. |
| MAX_GET_STRING_SIZE: Number = 10485760 | The maximum size for get() returning a String is five times the default size for getting a String. |
| Property | Description |
|---|---|
connected: Boolean (read-only) | Identifies if the FTP client is currently connected to the FTP server. |
replyCode: Number (read-only) | Returns the reply code from the last FTP action. |
replyMessage: String (read-only) | Returns the string message from the last FTP action. |
| timeout: Number | Returns the timeout for this client, in milliseconds. |
| Constructor | Description |
|---|---|
| FTPClient() | Constructs the FTPClient instance. |
| Method | Description |
|---|---|
| cd(String) | Changes the current directory on the remote server to the given path. |
| connect(String) | Connects and logs on to an FTP Server as “anonymous” and returns a boolean indicating success or failure. |
| connect(String, Number) | Connects and logs on to an FTP Server as “anonymous” and returns a boolean indicating success or failure. |
| connect(String, Number, String, String) | Connects and logs on to an FTP server and returns a boolean indicating success or failure. |
| connect(String, String, String) | Connects and logs on to an FTP server and returns a boolean indicating success or failure. |
| del(String) | Deletes the remote file on the server identified by the path parameter. |
| disconnect() | The method first logs the current user out from the server and then disconnects from the server. |
| get(String) | Reads the content of a remote file and returns it as a string using “ISO-8859-1” encoding to read it. |
| Reads the content of a remote file and returns it as a string using “ISO-8859-1” encoding to read it. | |
| get(String, String) | Reads the content of a remote file and returns it as string using the passed encoding. |
| get(String, String, File) | Reads the content of a remote file and creates a local copy in the given file using the passed string encoding to read the file content and using the system standard encoding “UTF-8” to write the file. |
| Reads the content of a remote file and creates a local copy in the given file using the passed string encoding to read the file content and using the system standard encoding “UTF-8” to write the file. | |
| Reads the content of a remote file and returns it as a string using the specified encoding. | |
| getBinary(String, File) | Reads the content of a remote file and creates a local copy in the given file. |
| Reads the content of a remote file and creates a local copy in the given file. | |
| getConnected() | Identifies if the FTP client is currently connected to the FTP server. |
| getReplyCode() | Returns the reply code from the last FTP action. |
| getReplyMessage() | Returns the string message from the last FTP action. |
| getTimeout() | Returns the timeout for this client, in milliseconds. |
| list() | Returns a list of FTPFileInfo objects containing information about the files in the current directory. |
| list(String) | Returns a list of FTPFileInfo objects containing information about the files in the remote directory defined by the given path. |
| mkdir(String) | Creates a directory |
| put(String, String) | Puts the specified content to the specified full path using “ISO-8859-1” encoding. |
| put(String, String, String) | Put the given content to a file on the given full path on the FTP server. |
| putBinary(String, File) | Put the content of the given file into a file on the remote FTP server with the given full path. |
| removeDirectory(String) | Deletes the remote directory on the server identified by the path parameter. |
| rename(String, String) | Renames an existing file. |
| setTimeout(Number) | Sets the timeout for connections made with the FTP client to the given number of milliseconds. |
assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values
The default size for get() returning a File is 5MB
Deprecated:
The default size is not supported anymore. The get() methods returning a file will
always try to return MAX_GET_FILE_SIZE bytes instead.
Warning
The default size for get() returning a String is 2MB
Deprecated:
The default size is not supported anymore. The get() methods returning a String will
always try to return MAX_GET_STRING_SIZE bytes instead.
Warning
The maximum size for get() returning a File is forty times the default size for getting a file. The
largest file allowed is 200MB.
The maximum size for get() returning a String is five times the default size for getting a String.
The largest String allowed is 10MB.
(read-only)Identifies if the FTP client is currently connected to the FTP server.
(read-only)Returns the reply code from the last FTP action.
(read-only)Returns the string message from the last FTP action.
Returns the timeout for this client, in milliseconds.
Constructs the FTPClient instance.
Changes the current directory on the remote server to the given path.
Parameters:
Returns:
Connects and logs on to an FTP Server as "anonymous" and returns a boolean indicating success or failure.
Parameters:
Returns:
Connects and logs on to an FTP Server as "anonymous" and returns a boolean indicating success or failure.
Parameters:
Returns:
Connects and logs on to an FTP server and returns a boolean indicating success or failure.
Parameters:
Returns:
Connects and logs on to an FTP server and returns a boolean indicating success or failure.
Parameters:
Returns:
Deletes the remote file on the server identified by the path parameter.
Parameters:
Returns:
The method first logs the current user out from the server and then disconnects from the server.
Reads the content of a remote file and returns it as a string using "ISO-8859-1" encoding to read it. Read at most MAX_GET_STRING_SIZE bytes.
Parameters:
Returns:
Reads the content of a remote file and returns it as a string using "ISO-8859-1" encoding to read it. Read at most maxGetSize characters.
Parameters:
Returns:
Deprecated:
The maxGetSize attribute is not supported anymore. Use the method get(String) instead.
Warning
Reads the content of a remote file and returns it as string using the passed encoding. Read at most MAX_GET_STRING_SIZE characters.
Parameters:
Returns:
Reads the content of a remote file and creates a local copy in the given file using the passed string encoding to read the file content and using the system standard encoding "UTF-8" to write the file. Copies at most MAX_GET_FILE_SIZE bytes.
Parameters:
Returns:
Reads the content of a remote file and creates a local copy in the given file using the passed string encoding to read the file content and using the system standard encoding "UTF-8" to write the file. Copies at most maxGetSize bytes.
Parameters:
Returns:
Deprecated:
The maxGetSize attribute is not supported anymore. Use the method get(String, String, File) instead.
Warning
Reads the content of a remote file and returns it as a string using the specified encoding. Returns at most maxGetSize characters.
Parameters:
Returns:
Deprecated:
The maxGetSize attribute is not supported anymore. Use the method get(String, String) instead.
Warning
Reads the content of a remote file and creates a local copy in the given file. Copies at most MAX_GET_FILE_SIZE bytes. The FTP transfer is done in Binary mode.
Parameters:
Returns:
Reads the content of a remote file and creates a local copy in the given file. Copies at most maxGetSize bytes. The FTP transfer is done in Binary mode.
Parameters:
Returns:
Deprecated:
The maxGetSize attribute is not supported anymore. Use the method getBinary(String, File) instead.
Warning
Identifies if the FTP client is currently connected to the FTP server.
Returns:
Returns the reply code from the last FTP action.
Returns:
Returns the string message from the last FTP action.
Returns:
Returns the timeout for this client, in milliseconds.
Returns:
Returns a list of FTPFileInfo objects containing information about the files in the current directory.
Returns:
Returns a list of FTPFileInfo objects containing information about the files in the remote directory defined by the given path.
Parameters:
Returns:
Creates a directory
Parameters:
Returns:
Puts the specified content to the specified full path using "ISO-8859-1" encoding. The full path must include the path and the file name. If the content of a local file is to be uploaded, please use method putBinary(String, File) instead.
Parameters:
Returns:
Put the given content to a file on the given full path on the FTP server. The full path must include the path and the file name. The transformation from String into binary data is done via the encoding provided with the method call. If the content of a local file is to be uploaded, please use method putBinary(String, File) instead.
Parameters:
Returns:
Put the content of the given file into a file on the remote FTP server with the given full path. The full path must include the path and the file name.
Parameters:
Returns:
Deletes the remote directory on the server identified by the path parameter. In order to delete the directory successfully the directory needs to be empty, otherwise the removeDirectory() method will return false.
Parameters:
Returns:
Renames an existing file.
Parameters:
Returns:
Sets the timeout for connections made with the FTP client to the given number of milliseconds. If the given timeout is less than or equal to zero, the timeout is set to the same value as the script context timeout but will only be set to a maximum of 30 seconds.
The maximum and default timeout depend on the script context timeout. The maximum timeout is set to a maximum of 2 minutes. The default timeout for a new client is set to a maximum of 30 seconds.
This method can be called at any time, and will affect the next connection made with this client. It is not possible to set the timeout for an open connection.
Parameters: