@@ -13,7 +13,20 @@ the SFTP protocol using [asyncssh](https://github.com/ronf/asyncssh).
13
13
14
14
## Tutorial
15
15
16
- Install the ` sshfs ` from PyPI or the conda-forge, and import it;
16
+ Install the ` sshfs ` from PyPI or the conda-forge. This will install ` fsspec `
17
+ and register ` sshfs ` for ` ssh:// ` urls, so you can open files using:
18
+
19
+ ``` py
20
+ from fsspec import open
21
+
22
+ with open (' ssh://[user@]host[:port]/path/to/file' , " w" ) as file :
23
+ file .write(" Hello World!" )
24
+
25
+ with open (' ssh://[user@]host[:port]/path/to/file' , " r" ) as file :
26
+ print (file .read())
27
+ ```
28
+
29
+ For more operations, you can use the ` SSHFileSystem ` class directly:
17
30
18
31
``` py
19
32
from sshfs import SSHFileSystem
@@ -43,6 +56,8 @@ fs = SSHFileSystem(
43
56
)
44
57
```
45
58
59
+ Note: you can also pass ` client_keys ` as an argument to ` fsspec.open ` .
60
+
46
61
All operations and their descriptions are specified [ here] ( https://filesystem-spec.readthedocs.io/en/latest/api.html#fsspec.spec.AbstractFileSystem ) .
47
62
Here are a few example calls you can make, starting with ` info() ` which allows you to retrieve the metadata about given path;
48
63
@@ -61,15 +76,15 @@ You can also create new files through either putting a local file with `put_file
61
76
``` py
62
77
>> > with fs.open(' /tmp/message.dat' , ' wb' ) as stream:
63
78
... stream.write(b ' super secret messsage!' )
64
- ...
79
+ ...
65
80
```
66
81
67
82
And either download it through ` get_file ` or simply read it on the fly with opening it;
68
83
69
84
``` py
70
85
>> > with fs.open(' /tmp/message.dat' ) as stream:
71
86
... print (stream.read())
72
- ...
87
+ ...
73
88
b ' super secret messsage!'
74
89
```
75
90
@@ -80,10 +95,10 @@ There are also a lot of other basic filesystem operations, such as `mkdir`, `tou
80
95
>> > fs.mkdir(' /tmp/dir/eggs' )
81
96
>> > fs.touch(' /tmp/dir/spam' )
82
97
>> > fs.touch(' /tmp/dir/eggs/quux' )
83
- >> >
98
+ >> >
84
99
>> > for file in fs.find(' /tmp/dir' ):
85
100
... print (file )
86
- ...
101
+ ...
87
102
/ tmp/ dir / eggs/ quux
88
103
/ tmp/ dir / spam
89
104
```
0 commit comments