| 1 |
import globus_sdk |
| 2 |
from globus_sdk.scopes import TransferScopes |
| 3 |
|
| 4 |
CLIENT_ID = "61338d24-54d5-408f-a10d-66c06b59f6d2" |
| 5 |
auth_client = globus_sdk.NativeAppAuthClient(CLIENT_ID) |
| 6 |
|
| 7 |
# requested_scopes specifies a list of scopes to request |
| 8 |
# instead of the defaults, only request access to the Transfer API |
| 9 |
auth_client.oauth2_start_flow(requested_scopes=TransferScopes.all) |
| 10 |
authorize_url = auth_client.oauth2_get_authorize_url() |
| 11 |
print(f"Please go to this URL and login:\n\n{authorize_url}\n") |
| 12 |
|
| 13 |
auth_code = input("Please enter the code here: ").strip() |
| 14 |
tokens = auth_client.oauth2_exchange_code_for_tokens(auth_code) |
| 15 |
transfer_tokens = tokens.by_resource_server["transfer.api.globus.org"] |
| 16 |
|
| 17 |
# construct an AccessTokenAuthorizer and use it to construct the |
| 18 |
# TransferClient |
| 19 |
transfer_client = globus_sdk.TransferClient( |
| 20 |
authorizer=globus_sdk.AccessTokenAuthorizer(transfer_tokens["access_token"]) |
| 21 |
) |
| 22 |
|
| 23 |
# Replace these with your own collection UUIDs |
| 24 |
source_collection_id = "..." |
| 25 |
dest_collection_id = "..." |
| 26 |
|
| 27 |
# create a Transfer task consisting of one or more items |
| 28 |
task_data = globus_sdk.TransferData( |
| 29 |
source_endpoint=source_collection_id, destination_endpoint=dest_collection_id |
| 30 |
) |
| 31 |
task_data.add_item( |
| 32 |
"/share/godata/file1.txt", # source |
| 33 |
"/~/minimal-example-transfer-script-destination.txt", # dest |
| 34 |
) |
| 35 |
|
| 36 |
# submit, getting back the task ID |
| 37 |
task_doc = transfer_client.submit_transfer(task_data) |
| 38 |
task_id = task_doc["task_id"] |
| 39 |
print(f"submitted transfer, task_id={task_id}") |