| 1 |
.. _example_minimal_transfer: |
| 2 |
|
| 3 |
File Transfer Scripts |
| 4 |
===================== |
| 5 |
|
| 6 |
Minimal File Transfer Script |
| 7 |
---------------------------- |
| 8 |
|
| 9 |
The following is an extremely minimal script to demonstrate a file transfer |
| 10 |
using the :class:`TransferClient <globus_sdk.TransferClient>`. |
| 11 |
|
| 12 |
It uses the tutorial client ID from the :ref:`tutorials <tutorials>`. |
| 13 |
For simplicity, the script will prompt for login on each use. |
| 14 |
|
| 15 |
.. note:: |
| 16 |
You will need to replace the values for ``source_collection_id`` and |
| 17 |
``dest_collection_id`` with UUIDs of collections that you have access to. |
| 18 |
|
| 19 |
.. literalinclude:: transfer_minimal.py |
| 20 |
:caption: ``transfer_minimal.py`` [:download:`download <transfer_minimal.py>`] |
| 21 |
:language: python |
| 22 |
|
| 23 |
|
| 24 |
Minimal File Transfer Script Handling ConsentRequired |
| 25 |
----------------------------------------------------- |
| 26 |
|
| 27 |
The above example works with certain endpoint types, but will fail if either |
| 28 |
the source or destination endpoint requires a ``data_access`` scope. This |
| 29 |
requirement will cause the Transfer submission to fail with a |
| 30 |
``ConsentRequired`` error. |
| 31 |
|
| 32 |
The example below catches the ``ConsentRequired`` error and retries the |
| 33 |
submission after a second login. |
| 34 |
|
| 35 |
This kind of "reactive" handling of ``ConsentRequired`` is the simplest |
| 36 |
strategy to design and implement. |
| 37 |
|
| 38 |
We'll also enhance the example to take endpoint IDs from the command line. |
| 39 |
|
| 40 |
.. literalinclude:: transfer_consent_required_reactive.py |
| 41 |
:caption: ``transfer_consent_required_reactive.py`` [:download:`download <transfer_consent_required_reactive.py>`] |
| 42 |
:language: python |
| 43 |
|
| 44 |
|
| 45 |
Best-Effort Proactive Handling of ConsentRequired |
| 46 |
------------------------------------------------- |
| 47 |
|
| 48 |
The above example works in most cases, and especially when there is a low cost |
| 49 |
to failing and retrying an activity. |
| 50 |
|
| 51 |
However, in some cases, responding to ``ConsentRequired`` errors when the task |
| 52 |
is submitted is not acceptable. For example, for scripts used in batch job |
| 53 |
systems, the user cannot respond to the error until the job is already |
| 54 |
executing. The user would rather handle such issues when submitting their job. |
| 55 |
|
| 56 |
``ConsentRequired`` errors in this case can be avoided on a best-effort basis. |
| 57 |
Note, however, that the process for consenting ahead of time is more error |
| 58 |
prone and complex. |
| 59 |
|
| 60 |
The example below enhances the previous reactive error handling to try an |
| 61 |
``ls`` operation before starting to build the task data. If the ``ls`` fails |
| 62 |
with ``ConsentRequired``, the user can be put through the relevant login flow. |
| 63 |
And if not, we can relatively safely assume that any errors are not relevant. |
| 64 |
|
| 65 |
.. literalinclude:: transfer_consent_required_proactive.py |
| 66 |
:caption: ``transfer_consent_required_proactive.py`` [:download:`download <transfer_consent_required_proactive.py>`] |
| 67 |
:language: python |