1. Download file to local system from Jupyter notebook

Download file to local system from Jupyter notebook

Home Forums FABRIC General Questions and Discussion Download file to local system from Jupyter notebook

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #6145
    Nishanth Shyamkumar
    Participant

      Hi,

      This question maybe have more to do with Jupyter notebook then FABRIC, but hopefully someone can suggest some ideas.
      I have a couple of compressed files on the Jupyter server that I want to download to my local computer. I can do this by right-clicking on the file and selecting ‘Download’.
      However, I want to automate this process, instead of manually clicking things. Is there a way to access the compressed files via wget or scp from the local system.

      #6148
      Ilya Baldin
      Participant

        What an excellent question!

        Yes JupyterHub has two levels of REST APIs – one – the JupyterHub API (for admins) the other the Notebook Server API accessible to users.

        You need to obtain the API token by going to Hub Control Panel (see the image)

        The APIs can be invoked using the following URL: https://jupyter.fabric-testbed.net/user/<username>/api

        where <username> is your primary email (in fact you should see it in your browser address field when you start the notebook, except it will look like https://jupyter.fabric-testbed.net/user/<username>/lab)

        You can use cURL to make the call (this shows how to start a particular notebook, moving files in and out is similar):

        curl -X POST -H "Authorization: token <token string>" "https://jupyter.fabric-testbed.net/user/<username>/api/sessions" -d '{"name":"configure_environment.ipynb","type":"notebook","path":"jupyter-examples-rel1.3.3/fabric_examples/fablib_api/configure_environment/configure_environment.ipynb"}'
        
        
        #6152
        Nishanth Shyamkumar
        Participant

          Thanks Ilya for the very useful answer. I was able to download my compressed file with a GET request via curl using this method.

          Just some additional information for others,
          1) To access the Hub Panel in Jupyter notebook, click on ‘File’->’Hub Control Panel’

          2) From here click on ‘Token’->’Request New API token’ and save the generated token number, which can be used in the curl request as a header (-H).

          I still have to look into generating tokens without manual intervention, that will close the automation loop. If there are any updates I will post them here.

          #6153
          Ilya Baldin
          Participant

            Nishanth,

            I do not believe it is possible to automate getting the token – it requires someone to login using your credentials. However the token should be good for a while – you should be able to select the lifetime.

            Also please note that the token allows access to your container via API without any other checks – if someone steals it they may act on your behalf in the container so long as you have an active container (e.g. upload and execute a notebook) or wipe its contents clean. You must secure the token. Be mindful of e.g. uploading into GitHub or sharing it with others.

            #6154
            Nishanth Shyamkumar
            Participant

              Thanks, I agree with you Ilya. I have seen some of the APIs in the link you shared, and they can delete files, and shutdown the kernel etc. which is a huge security risk.
              It’s probably more pragmatic to download using the right click option via the UI.

              #6155
              Ilya Baldin
              Participant

                The APIs are enabled for your use, you do need to use them judiciously and keep in mind that if you can invoke them, so can someone else if they have your token.

              Viewing 6 posts - 1 through 6 (of 6 total)
              • You must be logged in to reply to this topic.