Using Rclone for File Transfer

Rclone is an open source file transfer tool to make transfering files to and from various cloud resources such as Box, Amazon S3, Microsoft OneDrive, and Google Cloud Storage and your local machine a simpler task. Guides on how to set up a variety of resources to transfer to and from can be found at rclone’s webpage.

This tool can be used to transfer files between HCC clusters and outside cloud providers, such as Box.

Setup RClone

  1. You must be able to access your UNL Box.com, UNK Box.com, UNO Box.com, or UNMC Box.com account before beginning this process. Contact your local campus support if you need help with initial account setup.

  2. Due to the clusters being remote machines, Rclone will need to be installed on your local machine in order to authorize Box. Some services, such as Google Drive, do not require Rclone to be installed on your local machine.

  3. After logging into the cluster of your choice, load the rclone module by entering the command below at the prompt:

    Load the Rclone module
    [demo2@login.crane ~]$ module load rclone

  4. We will need to start the basic configuration for box. To do this run rclone config:

    Load the rclone config
    [demo2@login.crane ~]$ rclone config

  5. In a new configuration, you will see no remotes found. Enter n to make a new remote and name it a name you will know. In our example, we will use “MyBox”. Select box by entering in the corresponding number, in our case 6. Hit Enter for the client_id and client_secret and y for Edit advanced config. Due to the file size limit with Box, set the upload_cutoff to 15G and press enter, also leaving the commit_retries as the default by pressing Enter. When you are prompted for auto config, select N. The terminal will stop at a result> prompt. Proceed to the next step.

    Configure box
    [demo2@login.crane ~]$ rclone config
    No remotes found - make a new one
    n) New remote
    s) Set configuration password
    q) Quit config
    n/s/q> n
    name> MyBox
    Type of storage to configure.
    Enter a string value. Press Enter for the default ("").
    Choose a number from below, or type in your own value
    
     6 / Box
       \ "box"
    
    Storage> 6
    
    Box App Client Id.
    Leave blank normally.
    Enter a string value. Press Enter for the default ("").
    client_id>
    Box App Client Secret
    Leave blank normally.
    Enter a string value. Press Enter for the default ("").
    client_secret>
    Edit advanced config? (y/n)
    y) Yes
    n) No
    y/n> y
    Cutoff for switching to multipart upload (>= 50MB).
    Enter a size with suffix k,M,G,T. Press Enter for the default ("50M").
    upload_cutoff> 15G
    Max number of times to try committing a multipart file.
    Enter a signed integer. Press Enter for the default ("100").
    commit_retries>
    Remote config
    Use auto config?
     \* Say Y if not sure
     \* Say N if you are working on a remote or headless machine
    y) Yes
    n) No
    y/n> n
    For this to work, you will need Rclone available on a machine that has a web browser available.
    Execute the following on your machine:
            rclone authorize "box"
    Then paste the result below:
    result>

  6. Now switch to a terminal on your local machine and run rclone authorize "box". You will be prompted to go to a 127.0.0.1 address in your web browser if a browser doesn’t open automatically. Select Use Single Sign On(SSO) at the bottom and then enter in your NU e-mail address. You will be taken to sign into your campus’ Box instance using your TrueYou/campus credentials. Select Grant access to Box. You will be told to paste a line of code from your local machine to the cluster and then to confirm that the config is correct.

    Authorize Box on local machine
    [myaccount@local.machine ~]$ rclone authorize "box"
    Local Authorization after logging in with browser
    [myaccount@local.machine ~]$ rclone authorize "box"
    If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth
    Log in and authorize Rclone for access
    Waiting for code...
    Got code
    Paste the following into your remote machine --->
    {"access_token":"XXXX","token_type":"bearer","refresh_token":"XXXX","expiry":"XXXX"}
    <---End paste
    For other services, please refer to the rclone documentation.

  7. Returning to the cluster, now paste the code into the waiting result prompt, then press y to confirm and q to exit.

    Authorize Box on cluster
    result> {"access_token":"XXXX","token_type":"bearer","refresh_token":"XXXX","expiry":"XXXX"}
    --------------------
    [Box]
    type = box
    box_sub_type = user
    upload_cutoff = 15G
    token = {"access_token":"XXXX","token_type":"bearer","refresh_token":"XXXX","expiry":"XXXX"}
    --------------------
    y) Yes this is OK
    e) Edit this remote
    d) Delete this remote
    y/e/d> y
    Current remotes:
    
    Name                 Type
    ====                 ====
    Box                  box
    
    e) Edit existing remote
    n) New remote
    d) Delete remote
    r) Rename remote
    c) Copy remote
    s) Set configuration password
    q) Quit config
    e/n/d/r/c/s/q> q
    Now test the connection by running the ls command. You should see a listing of your Box files.
    List contents of Box
    [demo2@login.crane ~]$ rclone ls MyBox:/

  8. To upload or download files, use the clone command. For example:

    Transferring files
    [demo2@login.crane ~]$ rclone copy MyBox:/SomeFile.txt ./
    [demo2@login.crane ~]$ rclone copy ./SomeFile.txt MyBox:/

  9. To download directories, use the clone command and use directory names over file. This copies the contents of the folders, so you need to specify a destination folder.

    Download a directory from Box
    [demo2@login.crane ~]$ rclone copy MyBox:/my_hcc_dir ./my_hcc_dir
    To upload a directory named my_hcc_dir to Box, use clone.
    Upload a directory to Box
    [demo2@login.crane ~]$ rclone copy ./my_hcc_dir MyBox:/my_hcc_dir

  10. Rclone also supports using sync to transfer files, similar to rsync. The syntax is similar to rclone copy. This would only transfer files that are updated by name, checksum, or time. The exmaple below would sync the files of the local directory to the remote directory on box.

    transfer.sh
    [demo2@login.crane ~]$ rclone sync ./my_hcc_dir MyBox:/my_hcc_dir