Skip to content

SFTP Actions

SFTP Actions allow Marvin to interact with SFTP file servers.

Actions

sftp.change_dir

Change the current directory on SFTP

Parameters:

sftp - SFTP client created by sftp.connect

directory - Path to new directory. This value could be relative or complete path to new folder

Returns:

current_folder - Path to new folder selected

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.change_dir($sftp, '../newFolder')
sftp.change_dir($sftp, '/base_path/newFolder')

sftp.chdir

Change the current directory on SFTP

Parameters:

sftp - SFTP client created by sftp.connect

directory - Path to new directory. This value could be relative or complete path to new folder

Returns:

current_folder - Path to new folder selected

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.chdir($sftp, '../newFolder')
sftp.chdir($sftp, '/base_path/newFolder')

sftp.close

Closes connection to SFTP server

Parameters:

sftp - SFTP client created by sftp.connect

Returns:

sftp - Will be deleted from Marvin Vars

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.close($sftp)

sftp.create_folder

Creates a new folder on SFTP Server.

Parameters:

sftp - SFTP client created by sftp.connect

remote_path - Complete path to folder creation.

mode (optional)- File access mode for new folder (default=777)

Returns:

This action gives no return

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.create_folder($sftp, '/base_folder/newFolder/')

sftp.connect

Open a new connection to SFTP server

Parameters:

host - SFTP Server host

username - Username to connect on SFTP Server

password (optional)- Password to connect on SFTP Server, if passwrod is necessary to connect (default=no password)

port (optional)- SFTP Server port for connection (default=22)

default_path (optional)- Path where SFTP client must be after connection (default=root)

private_key (optional)- Path to private key used to connect (default=no private key needed)

private_key_pass=None - Password for the private key used to connect (default=no private key password needed)

Returns:

sftp - SFTP client

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.connect('test.rebex.net', 'demo', 'password', 22)

sftp.current_folder

Return the path of current folder.

Parameters:

sftp - SFTP client created by sftp.connect

Returns:

current_folder - Path to new folder selected

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.current_folder($sftp)
prompt.alert($current_folder)

sftp.delete

Deletes the given file or folder

Parameters:

sftp - SFTP client created by sftp.connect

remote_path - Path to the file or folder to be deleted.

Returns:

This action gives no return

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.delete($sftp, '../newFolder/my-file.txt')

sftp.download

Downloads a file from SFTP Server.

Parameters:

sftp - SFTP client created by sftp.connect

remote_path - Path to the file or folder to be deleted.

local_path - Path to local machine, where file must be saved

Tip

Don't forget to include file name on local_path

Returns:

download_path - Local path to downloaded file

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.download($sftp, 'readme.txt', 'tests/sftp_download.txt')

sftp.file_exists

Verify is a file exists on SFTP Server.

Parameters:

sftp - SFTP client created by sftp.connect

remote_path - Remote path for the file

Returns:

exists - True if file exists on server False if don't

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.file_exists($sftp, '/base_path/newFolder/my-file.txt')

sftp.folder_exists

Verify is a folder exists on SFTP Server.

Parameters:

sftp - SFTP client created by sftp.connect

remote_path - Remote path for the folder

Returns:

exists - True if folder exists on server False if don't

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.folder_exists($sftp, '/base_path/newFolder')

sftp.list

List all files and folder on current path or on the given remote path.

Parameters:

sftp - SFTP client created by sftp.connect

remote_path (optional)- Remote path to folder which files and folders must be listed (default=current path)

Returns:

items - Name of all files and folder inside currrent path or given remote_path

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.list($sftp)
for item in $items:
    prompt.alert(item)

sftp.list($sftp, '/base_path/newFolder')
for item in $items:
    prompt.alert(item)

sftp.list_files

List all files on current path or on the given remote path.

Parameters:

sftp - SFTP client created by sftp.connect

remote_path (optional)- Remote path to folder which files must be listed (default=current path)

Returns:

files - Name of all files inside currrent path or given remote_path

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.list_files($sftp)
for item in $files:
    prompt.alert(item)

sftp.list_files($sftp, '/base_path/newFolder')
for item in $files:
    prompt.alert(item)

sftp.list_folders

List all folders on current path or on the given remote path.

Parameters:

sftp - SFTP client created by sftp.connect

remote_path (optional)- Remote path to folder which folders must be listed (default=current path)

Returns:

folders - Name of all folder inside currrent path or given remote_path

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.list_folders($sftp)
for item in $folders:
    prompt.alert(item)

sftp.list_folders($sftp, '/base_path/newFolder')
for item in $folders:
    prompt.alert(item)

sftp.upload

Uploads a local file to SFTP Server on the current folder.

Parameters:

sftp - SFTP client created by sftp.connect

local_path - Local path to the file to be uploaded

Returns:

This action given o return

Exceptions:

This action gives no Exceptions

Usage Example
script.mvn
sftp.upload($sftp, 'c:/Temp/my-file.txt')