Python API
FTP
- class RPA.FTP.FTP
FTP library can be used to access an FTP server, and interact with files.
The library is based on Python’s built-in ftplib.
Examples
Robot Framework
*** Settings *** Library RPA.FTP *** Variables *** ${HOST} 127.0.0.1 ${PORT} 27345 ${USER} user ${PASS} 12345 *** Tasks *** List files on the server directory Connect ${HOST} ${PORT} ${USER} ${PASS} @{files} List Files FOR ${file} IN @{files} Log ${file} END
Python
from RPA.FTP import FTP library = FTP() library.connect('127.0.0.1', 27345, 'user', '12345') files = library.list_files() for f in files: print(f)
- ROBOT_LIBRARY_DOC_FORMAT = 'REST'
- ROBOT_LIBRARY_SCOPE = 'GLOBAL'
- abort() bool
Abort a file transfer in progress
- Returns
true or false based on success or failure
- close() None
Close connection to the server unilaterally
- connect(host: str, port: int = 21, user: Optional[str] = None, password: Optional[str] = None, tls: bool = False, transfer: str = 'passive', keyfile: Optional[str] = None, certfile: Optional[str] = None, timeout: Optional[int] = None, source_address: Optional[Tuple[str, int]] = None) bool
Connect to FTP server
- Parameters
host – address of the server
port – port of the server, defaults to 21
user – login name, defaults to None
password – login password, defaults to None
tls – connect using TLS support, defaults to False
transfer – mode of the transfer, defaults to “passive”
keyfile – path to private key file
certfile – path to certificate file
timeout – a timeout in seconds for the connection attempt
source_address – socket to bind to as its source address before connecting
- Raises
AuthenticationException – on authentication error with the server
- Returns
true if the connnection completes and an error code if it fails
- cwd(dirname: str) bool
Change working directory on the server
- Parameters
dirname – name of the directory
- Returns
true or false based on success or failure
- delete(filepath: str) bool
Delete file on the server
- Parameters
filepath – path to server file
- Returns
true or false based on success or failure
- download(remotefile: str, localfile: Optional[str] = None) bool
Download file from FTP server
- Parameters
remotefile – path to remote file on the server
localfile – name of the downloaded file on the local filesystem, if None will have same name as remote file
- Returns
true or false based on success or failure
- file_size(filepath: str) int
Return byte size of the file on the server
- Parameters
filepath – path to server file
- Returns
byte size as an int
- get_welcome_message() str
Get server welcome message
- Returns
welcome message as a string
- list_files(dirname: str = '') list
List files on the server directory
- Parameters
dirname – name of the directory
- Returns
list of files present in the server directory
- mkd(dirname: str) bool
Create a new directory on the server
- Parameters
dirname – name of the directory
- Returns
true or false based on success or failure
- pwd() str
Get current working directory on the server
- Returns
current working directory name as a string
- quit() None
Send QUIT command to the server and close connection
- rename(fromname: str, toname: str) bool
Rename file on the server
- Parameters
fromname – current name of the file
toname – new name for the file
- Returns
true or false based on success or failure
- rmd(dirname: str) bool
Remove directory on the server
- Parameters
dirname – name of the directory
- Returns
true or false based on success or failure
- send_command(command: str) bool
Execute command on the server
List of FTP commands: https://en.wikipedia.org/wiki/List_of_FTP_commands
- Parameters
command – name of the command to send
- Returns
true or false based on success or failure
- set_ascii_mode() bool
Set transfer mode to ASCII
- Returns
true or false based on success or failure
- set_binary_mode() bool
Set transfer mode to BINARY
- Returns
true or false based on success or failure
- set_debug_level(level: int = 0) bool
Set debug level for the library
- Parameters
level – integer value of debug level, defaults to 0
- Returns
true or false based on success or failure
0 - no debugging output 1 - moderate amount of debugging 2+ - higher amount of debugging
- upload(localfile: str, remotefile: str) bool
Upload file to FTP server
- Parameters
localfile – path to file to upload
remotefile – name of uploaded file in the server
- Returns
true or false based on success or failure