RedSSH.scp

class redssh.scp.RedSCP(ssh_session)[source]

Bases: object

Warning

This will only interact with the remote server as the user you logged in as, not the current user you are running commands as.

list_dir(remote_path)[source]

List a directory or path on the remote server.

Returns a dictionary of 'dirs' and 'files' as the top level keys, below that is all the file names as the keys and the values of those is the file attributes obtained from listing the directory. Inlcudes, file size, datetime modified and all the permissions for that file.

Parameters

remote_path (str) – Path to list on the remote server.

Returns

dict

mkdir(remote_path, dir_mode)[source]

Makes a directory using SCP on the remote server.

Parameters
  • remote_path (str) – Path the directory is going to be made at on the remote server.

  • dir_mode (int) – File mode in decimal (not the octal value) for the directory being created.

Returns

None

put_file(local_path, remote_path)[source]

Upload file via SCP to the remote session. Similar to scp /files/file user@host:/target. Also retains file permissions.

Parameters
  • local_path (str) – The local path to upload from.

  • remote_path (str) – The remote path to upload the local_path to.

put_folder(local_path, remote_path)[source]

Upload an entire folder via SCP to the remote session. Similar to scp /files/* user@host:/target Also retains file permissions.

Parameters
  • local_path (str) – The local path, on the machine where your code is running from, to upload from.

  • remote_path (str) – The remote path to upload the local_path to.

read(file_path, iter=True)[source]

Read from file over SCP on the remote server.

Parameters

file_path (str) – Remote file path to read from.

Returns

byte str or iter

write(local_path, remote_path)[source]

Write a local file to a remote file path over SCP on the remote server.

Parameters
  • local_path (str) – Local path to read from.

  • remote_path (str) – Remote path to write to.

Returns

None