IOHandler¶
- class pyremotedata.implicit_mount.IOHandler(local_dir: str | None = None, user_confirmation: bool = False, clean: bool = False, user: str | None = None, password: str | None = None, remote: str | None = None, lftp_settings: Dict[str, str] | None = None, **kwargs)[source]
Bases:
ImplicitMount
This is a high-level wrapper for the ImplicitMount class, which provides human-friendly methods for downloading files from a remote directory without the need to have technical knowledge on how to use LFTP.
To avoid SSH setup use lftp_settings = {‘sftp:connect-program’ : ‘ssh -a -x -i <keyfile>’}, user = <USER>, remote = <REMOTE>.
OBS: The attributes of this method should not be used unless for development or advanced use cases, all responsibility in this case is on the user.
- Parameters:
local_dir (str) – The local directory to use for downloading files. If None, a temporary directory will be used (suggested, unless truly necessary).
user_confirmation (bool) – If True, the user will be asked for confirmation before deleting files. (strongly suggested for debugging and testing)
clean (bool) – If True, the local directory will be cleaned after the context manager is exited. (suggested, if not it may lead to rapid exhaustion of disk space)
lftp_settings (Optional[Dict[str, str]]) – Add any additional settings or setting overrides (see https://lftp.yar.ru/lftp-man.html). The most common usecase is properly to use lftp_settings = {‘sftp:connect-program’ : ‘ssh -a -x -i <keyfile>’}. The defaults can also be overwritten by changing the PyRemoteData config file.
user (Optional[str]) – The username to use for connecting to the remote directory.
password (Optional[str]) – The SFTP password to possibly use when connecting to the remote host.
remote (Optional[str]) – The remote server to connect to.
**kwargs – Keyword arguments to pass to the ImplicitMount constructor.
- clone(local_destination: str | None, blocking: bool = True, **kwargs) List[str] | None [source]
Clones the current remote directory to the given local destination.
- Parameters:
- Returns:
The output of ImplicitMount.mirror, which depend on the arguments passed to the function. Most likely a list of the newly downloaded files.
- download(remote_path: str | List[str], local_destination: str | List[str] | None = None, blocking: bool = True, **kwargs) str | List[str] [source]
Downloads one or more files or a directory from the remote directory to the given local destination.
- Parameters:
remote_path (Union[str, List[str]]) – The remote path(s) to download.
local_destination (Union[str, List[str]]) – The local destination to download the file(s) to. If None, the file(s) will be downloaded to the current local directory.
blocking (bool) – If True, the function will block until the download is complete.
**kwargs – Extra keyword arguments are passed to the IOHandler.multi_download, IOHandler.pget or IOHandler.mirror functions depending on the type of the remote path(s).
- Returns:
(List of) The local path of the downloaded file(s) or directory.
- get_file_index(skip: int = 0, nmax: int | None = None, override: bool = False, store: bool = True, pattern: str | None = None) List[str] [source]
Get a list of files in the current remote directory.
- Parameters:
skip (int) – The number of files to skip.
nmax (int) – The maximum number of files to include.
override (bool) – If True, the file index will be overridden if it already exists.
store (bool) – If True, the file index will be stored on the remote directory.
pattern (str) – A regular expression pattern to filter the file names by, e.g. “.txt$” to only include files with the “.txt” extension.
- Returns:
A list of files in the current remote directory.
- lcd(local_path: str)[source]
Changes the current local directory using the LFTP command lcd.
- Parameters:
local_path (str) – The local directory to change to.
- lpwd()[source]
Get the current local directory using the LFTP command lpwd.
- Returns:
The current local directory.
- Return type: