Python API

FTP

exception RPA.FTP.AuthenticationException

Bases: Exception

Raised when server authentication fails

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class RPA.FTP.FTP

Bases: object

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

close()

Close connection to the server unilaterally

connect(host: str, port: int = 21, user: str = None, password: str = None, tls: bool = False, transfer: str = 'passive', keyfile: str = None, certfile: str = None, timeout: int = None, source_address: Tuple[str, int] = None)

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

cwd(dirname: str) → bool

Change working directory on the server

Parameters

dirname – name of the directory

delete(filepath: str) → bool

Delete file on the server

Parameters

filepath – path to server file

download(remotefile: str, localfile: 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

file_size(filepath: str) → int

Return byte size of the file on the server

Parameters

filepath – path to server file

get_welcome_message() → str

Get server welcome message

Returns

welcome message

list_files(dirname: str = '') → list

List files on the server directory

Parameters

dirname – name of the directory

mkd(dirname: str) → bool

Create a new directory on the server

Parameters

dirname – name of the directory

pwd() → str

Get current working directory on the server

quit()

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

rmd(dirname: str) → bool

Remove directory on the server

Parameters

dirname – name of the directory

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

set_ascii_mode()

Set transfer mode to ASCII

set_binary_mode()

Set transfer mode to BINARY

set_debug_level(level: int = 0) → bool

Set debug level for the library

Parameters

level – integer value of debug level, defaults to 0

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

exception RPA.FTP.FTPException

Bases: Exception

Raised on general FTP error

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

RPA.FTP.ftpcommand(f)