pyats.utils.fileutils.plugins.localhost.ftp package

Submodules

File utils class for FTP on Linux servers.

NOTE : The author is expected to subclass all base class operations not supported by this protocol and raise a NotImplementedError.

class pyats.utils.fileutils.plugins.localhost.ftp.fileutils.FileUtils(*args, os='localhost', protocol=None, **kwargs)

Bases: FileUtils

Initialize an instance of FileUtils

Parameters:
  • os (str) – The operating system of the device acting as a file transfer client.

  • testbed (pyats.topology.Testbed) – The testbed object that contains auth and address details for servers referenced by file transfer URLs.

PROGRESS_IGNORE_COUNT = 30
chmod(target, mode, timeout_seconds, *args, strip_leading_slash=True, **kwargs)

Change file permissions

Parameters:
  • target (str) – The URL of the file whose permissions are to be changed.

  • mode (int) – Same format as os.chmod

  • timeout_seconds (int) – Maximum allowed amount of time for the operation.

  • strip_leading_slash (bool) – If True, strip any leading slash from the remote path. If False, do not strip leading slash from the remote path.

Return type:

None if operation succeeded.

copyfile(source, destination, timeout_seconds, *args, upload, strip_leading_slash=True, **kwargs)

Copy a single file.

Copy a single file either from local to remote, or remote to local. Remote to remote transfers are not supported. Users are expected to make two calls to this API to do this.

Parameters:
  • timeout_seconds (int) – The number of seconds to wait before aborting the operation.

  • upload (bool) – If True, copying from local to remote. If False, copying from remote to local.

  • strip_leading_slash (bool) – If True, strip any leading slash from the remote path. If False, do not strip leading slash from the remote path.

:raises Exception : When a remote to remote transfer is requested.:

deletefile(target, timeout_seconds, *args, strip_leading_slash=True, **kwargs)

Delete a file

Parameters:
  • target (str) – The URL of the file to be deleted.

  • timeout_seconds (int) – Maximum allowed amount of time for the operation.

  • strip_leading_slash (bool) – If True, strip any leading slash from the remote path. If False, do not strip leading slash from the remote path.

dir(target, timeout_seconds, *args, strip_leading_slash=True, **kwargs)

Retrieve filenames contained in a directory.

Do not recurse into subdirectories, only list files at the top level of the given directory.

Parameters:
  • target (str) – The URL of the directory whose files are to be retrieved.

  • timeout_seconds (int) – The number of seconds to wait before aborting the operation.

  • strip_leading_slash (bool) – If True, strip any leading slash from the remote path. If False, do not strip leading slash from the remote path.

Returns:

`list`

Return type:

List of filename URLs. Directory names are ignored.

getspace(target, timeout_seconds, *args, **kwargs)

get the available disk space from the file server, in bytes.

Parameters:
  • target (str) – The URL of the directory to check available space.

  • timeout_seconds (int) – Maximum allowed amount of time for the operation.

renamefile(source, destination, timeout_seconds, *args, strip_leading_slash=True, **kwargs)

Rename a file

Parameters:
  • source (str) – The URL of the file to be renamed.

  • destination (str) – The URL of the new file name.

  • timeout_seconds (int) – Maximum allowed amount of time for the operation.

  • strip_leading_slash (bool) – If True, strip any leading slash from the remote path. If False, do not strip leading slash from the remote path.

stat(target, timeout_seconds, *args, strip_leading_slash=True, **kwargs)

Retrieve file details such as length and permissions.

Parameters:
  • target (str) – The URL of the file whose details are to be retrieved.

  • timeout_seconds (int) – The number of seconds to wait before aborting the operation.

  • strip_leading_slash (bool) – If True, strip any leading slash from the remote path. If False, do not strip leading slash from the remote path.

Returns:

`os.stat_result`

Return type:

Filename details including size.

:raises Exception : timeout exceeded: :raises Exception : File was not found:

pyats.utils.fileutils.plugins.localhost.ftp.fileutils.filemode_to_mode(filemode)

Convert a filemode string to an os.stat.st_mode style number.

Example

>>> import stat
>>> my_filemode = "-rw-r--r--"
>>> stat.filemode(filemode_to_mode(my_filemode))
-rw-r--r--