Skip to content


Transfer and manipulate your files and folders using our FTP and SFTP.


pip install botcity-ftp-plugin

Instantiating the plugin

First, let's instantiate the plugin passing the information that we will use to connect to the ftp server.

hostname = "<SERVER_NAME>"
username = "<USER_LOGIN>"
password = "<USER_PASSWORD>"

# Instantiate the plugin
ftp = BotFTPPlugin(hostname, username, password)


If no username and password are passed, the login attempt to the server will be done using an anonymous user by default. Some servers do not allow anonymous login, so pay attention to this.

File operations

With this plugin we can do the most basic operations with files and easily manage local files and files that are on the server.


Before performing file operations, make sure you are in the correct directory.

Use the set_current_directory method to set your current working directory on the server.

Uploading and downloading

# Connecting to server
ftp = BotFTPPlugin("<FTP_SERVER>", "<USER>", "<PASSWORD>")

# Uploading a local file named example.txt to the server

# Downloading a file named README stored on the server and saving in the local path: ftp_files/Downloads
ftp.download_file('README', 'ftp_files/Downloads')

# Closes the connection with the server

Renaming and deleting

# Renaming the file named "my_file.txt" stored on the server.
ftp.rename_file('my_file.txt', 'my_updated_file.txt')

# Deleting a file from the server by name


When renaming a file you can also pass a full path instead of just the file name. In this case, the file in addition to being renamed will be moved to the path that was passed.

Folder operations

It is also possible to do basic operations with the directories present on the server.

ftp = BotFTPPlugin("<FTP_SERVER>", "<USER>", "<PASSWORD>")

# Prints the path of the current working directory.
current_folder = ftp.get_current_directory()

# Prints the list of all files and folders contained in the current working directory

# Remove the specified directory from the server

# Create a new directory on the server. The full path of the created directory will be returned.
dir_path = ftp.create_directory('my_directory')

# Changes the current working directory to the new created directory

Complete code

Let's take a look into the complete code:

from botcity.plugins.ftp import BotFTPPlugin

# Connecting to server
ftp = BotFTPPlugin("<FTP_SERVER>", "<USER>", "<PASSWORD>")

# Creating a new directory and setting it to the current working directory
dir_path = ftp.create_directory('tests/my_directory')

# For each file in the local folder, upload it to the folder created on the server
local_folder = 'downloads/files'
for file in os.listdir(local_folder):
    ftp.upload_file(os.path.join(local_folder, file))


# Closes the connection with the server

Working with SFTP servers

In addition to managing files on an FTP server, with this plugin it is also possible to perform the same operations shown above on SFTP servers through an SSH connection.

To use these same operations on an SFTP server, just instantiate an object of the BotSFTPPlugin class.

from botcity.plugins.ftp import BotSFTPPlugin

# Connecting to server
sftp = BotSFTPPlugin("<SFTP_SERVER>", 22, "<USER>", "<PASSWORD>")

# Prints the name of each file in the current working directory
for file in sftp.get_files_list():

# Creating a new directory on the server

# Upload a file to the folder created on the server
sftp.upload_file("image.png", "folders/my_folder")

# Closes the connection with the server