Skip to main content
Modules

FTP

FTP

The FTP module is responsible for accessing an FTP server and handling files and directories.

Methods

connect

Method responsible for connecting to an FTP server. This connection is used for every other FTP action. FTP creates a connection between the user's device and a server, usually the equipment of the hosting service chosen. Through it, data can be exchanged between the systems when they are properly connected to the internet.

js
const connection = await FTP.connect.v1_0_0({
host: "ftp.exemplo.com.br",
port: 21,
user: "usuario",
password: "senha"
})

Required parameters

  • host: String - expects the address of the FTP server (IP or hostname).
  • port: Number - expects the port number of the FTP server. The default port is usually 21.

Optional parameters

  • user: String - expects the user name for the authentication on the FTP server.
  • password: String - expects the user password for the authentication on the FTP server.
  • connTimeout: Number - time limit in milliseconds to establish the connection.
  • pasvTimeout: Number - time limit in milliseconds for operations in passive mode.
  • keepalive: Number - interval in milliseconds to send keepalive packets.

Return

The constant or variable created, such as the connection of the example shown earlier, receives the FTP connection instance, which must be passed as the connection parameter in every other method of the FTP module.

createDir

Action responsible for creating a directory on an FTP server.

js
const createDir = await FTP.createDir.v1_0_0({
path: '',
recursive: true,
connection: connection
})

Required parameters

  • connection: expects an instance of the connect type with the names of the FTP servers already used before. Just select the one you want to use.
  • path: String - expects a string with the path of the directory. If you use only /, the directory is created at the root of the project.
  • recursive: Boolean - expects a boolean value indicating whether the name must be recursive or not. If you pass a path beyond the root and it does not exist, it is created.

Return

This method has no return.

deleteDir

Action responsible for deleting a directory on an FTP server.

js
const deleteDir = await FTP.deleteDir.v1_0_0({
path: '',
recursive: true,
connection: connection
})

Required parameters

  • connection: expects an instance of the connect type with the names of the FTP servers already used before. Just select the one you want to use.
  • path: String - expects a string with the path of the directory. If you use only /, the directory is created at the root of the project.
  • recursive: Boolean - expects a boolean value indicating whether the name must be recursive or not. If you pass a path beyond the root and it does not exist, it is created.

Return

This method has no return.

deleteFile

Action responsible for deleting a file on an FTP server.

js
const deleteFile = await FTP.deleteFile.v1_0_0({
path: '',
connection: connection
})

Required parameters

  • connection: expects an instance of the connect type with the names of the FTP servers already used before. Just select the one you want to use.
  • path: String - expects a string with the path of the file. The file name must be at the end of the path and accompanied by its extension. Example: /documents/pdfs/file.pdf.

Return

This method has no return.

disconnect

Action responsible for disconnecting from an FTP server.

js
const disconnect = await FTP.disconnect.v1_0_0({
connection: connection
})

Required parameters

  • connection: expects an instance of the connect type with the names of the FTP servers already used before. Just select the one you want to use.

Return

This method has no return.

getFile

Action responsible for downloading a file through an FTP server already opened earlier.

js
const getFile = await FTP.getFile.v1_0_0({
connection: connection,
localPath: '',
remotePath: ''
})

Required parameters

  • connection: expects an instance of the connect type with the names of the FTP servers already used before. Just select the one you want to use.
  • remotePath: String - expects a string with the path of the file. The file name must be at the end of the path and accompanied by its extension. Example: /documents/pdfs/file.pdf.
  • localPath: String - expects a string with the path where the file will be saved. The file name must be at the end of the path and accompanied by its extension. Example: C:\Users\Roberty\Downloads.

Return

This method has no return.

list

Action responsible for listing all the content of a directory.

js
const list = await FTP.list.v1_0_0({
connection: connection,
path: ''
})

Required parameters

  • connection: expects an instance of the connect type with the names of the FTP servers already used before. Just select the one you want to use.
  • path: String - expects a string that must be filled in with the path of the directory whose content you want to list. Example: /documents.

Return

The constant or variable created, such as the list of the example shown earlier, receives an object with the following properties:

  • list.count: Number - returns the total of items found in the directory.
  • list.items: Array - array with the items found. Each item has the following properties:
    • items[n].isDirectory: Boolean - indicates whether the item is a directory.
    • items[n].isFile: Boolean - indicates whether the item is a file.
    • items[n].name: String - name of the file or directory.
    • items[n].size: Number - size in bytes of the file/directory.
    • items[n].date: Date - date of the last modification.

move

Action responsible for renaming or moving a file/directory of an FTP server.

js
const move = await FTP.move.v1_0_0({
connection: connection,
oldPath: '',
newPath: ''
})

Required parameters

  • connection: expects an instance of the connect type with the names of the FTP servers already used before. Just select the one you want to use.
  • oldPath: String - expects a string that must be filled in with the current path of the directory/file. Example: /documents/action-plans/presentation.pdf.
  • newPath: String - expects a string that must be filled in with the new path of the directory/file. Example: /documents/plans/presentation.pdf.

Return

This method has no return.

putFile

Action responsible for sending a file through an FTP server already opened earlier.

js
const putFile = await FTP.putFile.v1_0_0({
connection: connection,
localPath: '',
remotePath: ''
})

Required parameters

  • connection: expects an instance of the connect type with the names of the FTP servers already used before. Just select the one you want to use.
  • remotePath: String - expects a string with the path where the file will be saved. The file name must be at the end of the path and accompanied by its extension. Example: /documents/pdfs/file.pdf.
  • localPath: String - expects a string with the path of the file. The file name must be at the end of the path and accompanied by its extension. Example: C:\Users\Roberty\Downloads.

Return

This method has no return.