scitacean.transfer.select.SelectFileTransfer#
- class scitacean.transfer.select.SelectFileTransfer(children, *, source_folder=None)[source]#
Upload / download files using a suitable transfer.
This file transfer selects one transfer out of a list of candidates and delegates to that transfer for all operations. The candidates are tried in the order they are provided and the first one that can connect and access a remote file or folder is used.
Examples
This uses a
LinkFileTransfer
if the files are directly accessible on the local system and falls back to anSFTPFileTransfer
otherwise.from scitacean.transfer.link import LinkFileTransfer from scitacean.transfer.select import SelectFileTransfer from scitacean.transfer.sftp import SFTPFileTransfer from scitacean import Client link_transfer = LinkFileTransfer() sftp_transfer = SFTPFileTransfer(host="fileserver") transfer = SelectFileTransfer([link_transfer, sftp_transfer]) client = Client.from_token(url="...", token="...", file_transfer=transfer)
Constructors
__init__
(children, *[, source_folder])Construct a new file transfer that selects from its children.
Methods
connect_for_download
(dataset, ...)Select a child transfer and connect it for downloading files.
connect_for_upload
(dataset, ...)Select a child transfer and connect it for uploading files.
source_folder_for
(dataset)Return the source folder used for the given dataset.
- __init__(children, *, source_folder=None)[source]#
Construct a new file transfer that selects from its children.
- Parameters:
children (
Iterable
[FileTransfer
]) – Child file transfers. For any given dataset upload or download, the children are tried in the given order.source_folder (
str
|RemotePath
|None
, default:None
) – Upload files to this folder if set. Otherwise, upload to the dataset’s source_folder. Ignored when downloading files.
- connect_for_download(dataset, representative_file_path)[source]#
Select a child transfer and connect it for downloading files.
Use this method as a context manager!
- Parameters:
dataset (
Dataset
) – The connection will be used to download files of this dataset.representative_file_path (
RemotePath
) – A path on the remote server to check whether files for this dataset can be read. The transfer assumes that, if it is possible to read from this path, it is possible to read from the paths of all files to be downloaded.
- Returns:
AbstractContextManager
[DownloadConnection
] – An open child connection.
- connect_for_upload(dataset, representative_file_path)[source]#
Select a child transfer and connect it for uploading files.
Use this method as a context manager!
- Parameters:
dataset (
Dataset
) – The connection will be used to upload files of this dataset.representative_file_path (
RemotePath
) – A path on the remote server to check whether files for this dataset can be written.
- Returns:
AbstractContextManager
[UploadConnection
] – An open child connection.