JupyterSCP


In [1]:
from jupyter_scp import JupyterSCP

Assuming that you have a secure.py in the current directory. The contents of secure.py should be as follows.

 sshdata = {
    "hostname": "misokatsu.tebasaki.nagoya-u.ac.jp",
    "username": "hitsumabushi",
    "key_file": "/Users/kishimen/.ssh/id_rsa",
    "key_pass": "0123"
}

In [2]:
import secure

In [3]:
scp = JupyterSCP(**secure.sshdata)

Exploring


In [4]:
scp.exe("date")


> Wed Aug 30 21:50:24 JST 2017

In [5]:
scp.ls()


> drwxr-xr-x   1 61422    1340         4096 28 Aug 19:43 lammps
> drwxr-xr-x   1 61422    1340         4096 22 May 15:43 intel
> drwxr-xr-x   1 61422    1340         4096 29 Aug 17:16 wget
> drwxr-xr-x   1 61422    1340         4096 29 Aug 23:52 notebooks

In [6]:
scp.ls(All=True)


> -rw-------   1 61422    1340          845 29 Aug 16:56 .bash_profile
> -rw-------   1 61422    1340          210 28 Aug 19:12 .bashrc
> drwxr-xr-x   1 61422    1340         4096 09 May 11:17 .hpcp
> -rw-------   1 61422    1340         7786 29 Aug 16:55 .viminfo
> drwx------   1 61422    1340         4096 29 May 13:29 .ssh
> drwxr-xr-x   1 61422    1340         4096 28 Aug 19:43 lammps
> -rw-------   1 61422    1340        29881 30 Aug 17:12 .bash_history
> drwxr-xr-x   1 61422    1340         4096 22 May 15:43 intel
> drwxr-xr-x   1 61422    1340         4096 29 Aug 17:16 wget
> drwxr-----   1 61422    1340         4096 10 Aug 12:50 .pki
> drwxr-xr-x   1 61422    1340         4096 29 Aug 10:26 .pyenv
> drwxr-xr-x   1 61422    1340         4096 29 Aug 02:18 .conda
> -rw-------   1 61422    1340         1024 12 Aug 12:29 .rnd
> drwx------   1 61422    1340         4096 29 Aug 20:09 .jupyter
> drwxr-xr-x   1 61422    1340         4096 16 Aug 03:30 .config
> drwxr-xr-x   1 61422    1340         4096 24 May 14:20 .subversion
> -rw-r--r--   1 61422    1340          209 30 May 14:31 .wget-hsts
> drwxr-xr-x   1 61422    1340         4096 29 Aug 23:52 notebooks
> drwxr-xr-x   1 61422    1340         4096 29 Aug 18:52 .ipython
> -rw-r--r--   1 61422    1340           20 29 Aug 16:47 .root_hist
> drwxr-xr-x   1 61422    1340         4096 29 Aug 19:09 .julia
> drwx------   1 61422    1340         4096 29 Aug 17:32 .local
> -rw-r--r--   1 61422    1340          296 29 Aug 19:28 .julia_history
> drwxr-xr-x   1 61422    1340         4096 29 Aug 22:10 .plotly
> drwxr-xr-x   1 61422    1340         4096 29 Aug 02:48 .cache
> drwxr-xr-x   1 61422    1340         4096 12 Aug 17:32 .emacs.d
> -rw-r--r--   1 61422    1340          280 29 Aug 17:39 .bash_runtime

In [7]:
scp.ls(All=True, Sort=True)


> -rw-------   1 61422    1340        29881 30 Aug 17:12 .bash_history
> -rw-------   1 61422    1340          845 29 Aug 16:56 .bash_profile
> -rw-r--r--   1 61422    1340          280 29 Aug 17:39 .bash_runtime
> -rw-------   1 61422    1340          210 28 Aug 19:12 .bashrc
> drwxr-xr-x   1 61422    1340         4096 29 Aug 02:48 .cache
> drwxr-xr-x   1 61422    1340         4096 29 Aug 02:18 .conda
> drwxr-xr-x   1 61422    1340         4096 16 Aug 03:30 .config
> drwxr-xr-x   1 61422    1340         4096 12 Aug 17:32 .emacs.d
> drwxr-xr-x   1 61422    1340         4096 09 May 11:17 .hpcp
> drwxr-xr-x   1 61422    1340         4096 29 Aug 18:52 .ipython
> drwxr-xr-x   1 61422    1340         4096 29 Aug 19:09 .julia
> -rw-r--r--   1 61422    1340          296 29 Aug 19:28 .julia_history
> drwx------   1 61422    1340         4096 29 Aug 20:09 .jupyter
> drwx------   1 61422    1340         4096 29 Aug 17:32 .local
> drwxr-----   1 61422    1340         4096 10 Aug 12:50 .pki
> drwxr-xr-x   1 61422    1340         4096 29 Aug 22:10 .plotly
> drwxr-xr-x   1 61422    1340         4096 29 Aug 10:26 .pyenv
> -rw-------   1 61422    1340         1024 12 Aug 12:29 .rnd
> -rw-r--r--   1 61422    1340           20 29 Aug 16:47 .root_hist
> drwx------   1 61422    1340         4096 29 May 13:29 .ssh
> drwxr-xr-x   1 61422    1340         4096 24 May 14:20 .subversion
> -rw-------   1 61422    1340         7786 29 Aug 16:55 .viminfo
> -rw-r--r--   1 61422    1340          209 30 May 14:31 .wget-hsts
> drwxr-xr-x   1 61422    1340         4096 22 May 15:43 intel
> drwxr-xr-x   1 61422    1340         4096 28 Aug 19:43 lammps
> drwxr-xr-x   1 61422    1340         4096 29 Aug 23:52 notebooks
> drwxr-xr-x   1 61422    1340         4096 29 Aug 17:16 wget

In [8]:
scp.cd("unagi")


No such file or directory.

In [9]:
scp.cd("wget")

In [10]:
scp.pwd()


> /home/usr3/z41743a/wget

In [11]:
scp.cd("..") # Go to the parent directory

In [12]:
scp.pwd()


> /home/usr3/z41743a

In [13]:
scp.cd("-") # Go to the ex-directory

In [14]:
scp.pwd()


> /home/usr3/z41743a/wget

In [15]:
scp.cd() # Go to the home directory

In [16]:
scp.pwd()


> /home/usr3/z41743a

Create and remove directory/file


In [17]:
scp.mkdir("testJupyterSCP")

In [18]:
scp.cd("testJupyterSCP")

In [19]:
cmd = """cat <<'__EOT__'>> test.txt
This is a test for JupyterSCP.
__EOT__
"""
scp.exe(cmd)

In [20]:
scp.cat("test.txt")


This is a test for JupyterSCP.


In [21]:
scp.mv("test.txt", "test_renamed.txt")

In [22]:
scp.chmod("test_renamed.txt", mode=744)

In [23]:
scp.ls()


> -rwxr--r--   1 61422    1340           31 30 Aug 21:50 test_renamed.txt

In [24]:
scp.cd("..")

In [25]:
scp.rm("testJupyterSCP")

In [26]:
scp.ls()


> drwxr-xr-x   1 61422    1340         4096 28 Aug 19:43 lammps
> drwxr-xr-x   1 61422    1340         4096 22 May 15:43 intel
> drwxr-xr-x   1 61422    1340         4096 29 Aug 17:16 wget
> drwxr-xr-x   1 61422    1340         4096 29 Aug 23:52 notebooks

File editor


In [4]:
scp.mkdir("testJupyterSCP")


Assuming testJupyterSCP/ already exists.

In [4]:
scp.cd("testJupyterSCP")

In [5]:
f_a = scp.edit("myFileA.txt")

In [7]:
f_a.save()

In [8]:
scp.cat("myFileA.txt")


A file is opened in Jupyter's editable mode.

In [7]:
f_a.reopen()

In [8]:
f_a.save()

In [9]:
scp.cat("myFileA.txt")


A file is opened in Jupyter's editable mode.
You can reopen the file.

In [10]:
scp.cd("..")

In [11]:
scp.rm("testJupyterSCP")

In [ ]: