github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/docs/content/commands/rclone_serve_sftp.md (about)

     1  ---
     2  date: 2020-02-01T10:26:53Z
     3  title: "rclone serve sftp"
     4  slug: rclone_serve_sftp
     5  url: /commands/rclone_serve_sftp/
     6  ---
     7  ## rclone serve sftp
     8  
     9  Serve the remote over SFTP.
    10  
    11  ### Synopsis
    12  
    13  rclone serve sftp implements an SFTP server to serve the remote
    14  over SFTP.  This can be used with an SFTP client or you can make a
    15  remote of type sftp to use with it.
    16  
    17  You can use the filter flags (eg --include, --exclude) to control what
    18  is served.
    19  
    20  The server will log errors.  Use -v to see access logs.
    21  
    22  --bwlimit will be respected for file transfers.  Use --stats to
    23  control the stats printing.
    24  
    25  You must provide some means of authentication, either with --user/--pass,
    26  an authorized keys file (specify location with --authorized-keys - the
    27  default is the same as ssh) or set the --no-auth flag for no
    28  authentication when logging in.
    29  
    30  Note that this also implements a small number of shell commands so
    31  that it can provide md5sum/sha1sum/df information for the rclone sftp
    32  backend.  This means that is can support SHA1SUMs, MD5SUMs and the
    33  about command when paired with the rclone sftp backend.
    34  
    35  If you don't supply a --key then rclone will generate one and cache it
    36  for later use.
    37  
    38  By default the server binds to localhost:2022 - if you want it to be
    39  reachable externally then supply "--addr :2022" for example.
    40  
    41  Note that the default of "--vfs-cache-mode off" is fine for the rclone
    42  sftp backend, but it may not be with other SFTP clients.
    43  
    44  
    45  ### Directory Cache
    46  
    47  Using the `--dir-cache-time` flag, you can set how long a
    48  directory should be considered up to date and not refreshed from the
    49  backend. Changes made locally in the mount may appear immediately or
    50  invalidate the cache. However, changes done on the remote will only
    51  be picked up once the cache expires.
    52  
    53  Alternatively, you can send a `SIGHUP` signal to rclone for
    54  it to flush all directory caches, regardless of how old they are.
    55  Assuming only one rclone instance is running, you can reset the cache
    56  like this:
    57  
    58      kill -SIGHUP $(pidof rclone)
    59  
    60  If you configure rclone with a [remote control](/rc) then you can use
    61  rclone rc to flush the whole directory cache:
    62  
    63      rclone rc vfs/forget
    64  
    65  Or individual files or directories:
    66  
    67      rclone rc vfs/forget file=path/to/file dir=path/to/dir
    68  
    69  ### File Buffering
    70  
    71  The `--buffer-size` flag determines the amount of memory,
    72  that will be used to buffer data in advance.
    73  
    74  Each open file descriptor will try to keep the specified amount of
    75  data in memory at all times. The buffered data is bound to one file
    76  descriptor and won't be shared between multiple open file descriptors
    77  of the same file.
    78  
    79  This flag is a upper limit for the used memory per file descriptor.
    80  The buffer will only use memory for data that is downloaded but not
    81  not yet read. If the buffer is empty, only a small amount of memory
    82  will be used.
    83  The maximum memory used by rclone for buffering can be up to
    84  `--buffer-size * open files`.
    85  
    86  ### File Caching
    87  
    88  These flags control the VFS file caching options.  The VFS layer is
    89  used by rclone mount to make a cloud storage system work more like a
    90  normal file system.
    91  
    92  You'll need to enable VFS caching if you want, for example, to read
    93  and write simultaneously to a file.  See below for more details.
    94  
    95  Note that the VFS cache works in addition to the cache backend and you
    96  may find that you need one or the other or both.
    97  
    98      --cache-dir string                   Directory rclone will use for caching.
    99      --vfs-cache-max-age duration         Max age of objects in the cache. (default 1h0m0s)
   100      --vfs-cache-mode string              Cache mode off|minimal|writes|full (default "off")
   101      --vfs-cache-poll-interval duration   Interval to poll the cache for stale objects. (default 1m0s)
   102      --vfs-cache-max-size int             Max total size of objects in the cache. (default off)
   103  
   104  If run with `-vv` rclone will print the location of the file cache.  The
   105  files are stored in the user cache file area which is OS dependent but
   106  can be controlled with `--cache-dir` or setting the appropriate
   107  environment variable.
   108  
   109  The cache has 4 different modes selected by `--vfs-cache-mode`.
   110  The higher the cache mode the more compatible rclone becomes at the
   111  cost of using disk space.
   112  
   113  Note that files are written back to the remote only when they are
   114  closed so if rclone is quit or dies with open files then these won't
   115  get written back to the remote.  However they will still be in the on
   116  disk cache.
   117  
   118  If using --vfs-cache-max-size note that the cache may exceed this size
   119  for two reasons.  Firstly because it is only checked every
   120  --vfs-cache-poll-interval.  Secondly because open files cannot be
   121  evicted from the cache.
   122  
   123  #### --vfs-cache-mode off
   124  
   125  In this mode the cache will read directly from the remote and write
   126  directly to the remote without caching anything on disk.
   127  
   128  This will mean some operations are not possible
   129  
   130    * Files can't be opened for both read AND write
   131    * Files opened for write can't be seeked
   132    * Existing files opened for write must have O_TRUNC set
   133    * Files open for read with O_TRUNC will be opened write only
   134    * Files open for write only will behave as if O_TRUNC was supplied
   135    * Open modes O_APPEND, O_TRUNC are ignored
   136    * If an upload fails it can't be retried
   137  
   138  #### --vfs-cache-mode minimal
   139  
   140  This is very similar to "off" except that files opened for read AND
   141  write will be buffered to disks.  This means that files opened for
   142  write will be a lot more compatible, but uses the minimal disk space.
   143  
   144  These operations are not possible
   145  
   146    * Files opened for write only can't be seeked
   147    * Existing files opened for write must have O_TRUNC set
   148    * Files opened for write only will ignore O_APPEND, O_TRUNC
   149    * If an upload fails it can't be retried
   150  
   151  #### --vfs-cache-mode writes
   152  
   153  In this mode files opened for read only are still read directly from
   154  the remote, write only and read/write files are buffered to disk
   155  first.
   156  
   157  This mode should support all normal file system operations.
   158  
   159  If an upload fails it will be retried up to --low-level-retries times.
   160  
   161  #### --vfs-cache-mode full
   162  
   163  In this mode all reads and writes are buffered to and from disk.  When
   164  a file is opened for read it will be downloaded in its entirety first.
   165  
   166  This may be appropriate for your needs, or you may prefer to look at
   167  the cache backend which does a much more sophisticated job of caching,
   168  including caching directory hierarchies and chunks of files.
   169  
   170  In this mode, unlike the others, when a file is written to the disk,
   171  it will be kept on the disk after it is written to the remote.  It
   172  will be purged on a schedule according to `--vfs-cache-max-age`.
   173  
   174  This mode should support all normal file system operations.
   175  
   176  If an upload or download fails it will be retried up to
   177  --low-level-retries times.
   178  
   179  ### Auth Proxy
   180  
   181  If you supply the parameter `--auth-proxy /path/to/program` then
   182  rclone will use that program to generate backends on the fly which
   183  then are used to authenticate incoming requests.  This uses a simple
   184  JSON based protocl with input on STDIN and output on STDOUT.
   185  
   186  There is an example program
   187  [bin/test_proxy.py](https://github.com/rclone/rclone/blob/master/test_proxy.py)
   188  in the rclone source code.
   189  
   190  The program's job is to take a `user` and `pass` on the input and turn
   191  those into the config for a backend on STDOUT in JSON format.  This
   192  config will have any default parameters for the backend added, but it
   193  won't use configuration from environment variables or command line
   194  options - it is the job of the proxy program to make a complete
   195  config.
   196  
   197  This config generated must have this extra parameter
   198  - `_root` - root to use for the backend
   199  
   200  And it may have this parameter
   201  - `_obscure` - comma separated strings for parameters to obscure
   202  
   203  For example the program might take this on STDIN
   204  
   205  ```
   206  {
   207  	"user": "me",
   208  	"pass": "mypassword"
   209  }
   210  ```
   211  
   212  And return this on STDOUT
   213  
   214  ```
   215  {
   216  	"type": "sftp",
   217  	"_root": "",
   218  	"_obscure": "pass",
   219  	"user": "me",
   220  	"pass": "mypassword",
   221  	"host": "sftp.example.com"
   222  }
   223  ```
   224  
   225  This would mean that an SFTP backend would be created on the fly for
   226  the `user` and `pass` returned in the output to the host given.  Note
   227  that since `_obscure` is set to `pass`, rclone will obscure the `pass`
   228  parameter before creating the backend (which is required for sftp
   229  backends).
   230  
   231  The progam can manipulate the supplied `user` in any way, for example
   232  to make proxy to many different sftp backends, you could make the
   233  `user` be `user@example.com` and then set the `host` to `example.com`
   234  in the output and the user to `user`. For security you'd probably want
   235  to restrict the `host` to a limited list.
   236  
   237  Note that an internal cache is keyed on `user` so only use that for
   238  configuration, don't use `pass`.  This also means that if a user's
   239  password is changed the cache will need to expire (which takes 5 mins)
   240  before it takes effect.
   241  
   242  This can be used to build general purpose proxies to any kind of
   243  backend that rclone supports.  
   244  
   245  
   246  ```
   247  rclone serve sftp remote:path [flags]
   248  ```
   249  
   250  ### Options
   251  
   252  ```
   253        --addr string                            IPaddress:Port or :Port to bind server to. (default "localhost:2022")
   254        --auth-proxy string                      A program to use to create the backend from the auth.
   255        --authorized-keys string                 Authorized keys file (default "~/.ssh/authorized_keys")
   256        --dir-cache-time duration                Time to cache directory entries for. (default 5m0s)
   257        --dir-perms FileMode                     Directory permissions (default 0777)
   258        --file-perms FileMode                    File permissions (default 0666)
   259        --gid uint32                             Override the gid field set by the filesystem. (default 1000)
   260    -h, --help                                   help for sftp
   261        --key string                             SSH private key file (leave blank to auto generate)
   262        --no-auth                                Allow connections with no authentication if set.
   263        --no-checksum                            Don't compare checksums on up/download.
   264        --no-modtime                             Don't read/write the modification time (can speed things up).
   265        --no-seek                                Don't allow seeking in files.
   266        --pass string                            Password for authentication.
   267        --poll-interval duration                 Time to wait between polling for changes. Must be smaller than dir-cache-time. Only on supported remotes. Set to 0 to disable. (default 1m0s)
   268        --read-only                              Mount read-only.
   269        --uid uint32                             Override the uid field set by the filesystem. (default 1000)
   270        --umask int                              Override the permission bits set by the filesystem. (default 2)
   271        --user string                            User name for authentication.
   272        --vfs-cache-max-age duration             Max age of objects in the cache. (default 1h0m0s)
   273        --vfs-cache-max-size SizeSuffix          Max total size of objects in the cache. (default off)
   274        --vfs-cache-mode CacheMode               Cache mode off|minimal|writes|full (default off)
   275        --vfs-cache-poll-interval duration       Interval to poll the cache for stale objects. (default 1m0s)
   276        --vfs-case-insensitive                   If a file name not found, find a case insensitive match.
   277        --vfs-read-chunk-size SizeSuffix         Read the source objects in chunks. (default 128M)
   278        --vfs-read-chunk-size-limit SizeSuffix   If greater than --vfs-read-chunk-size, double the chunk size after each chunk read, until the limit is reached. 'off' is unlimited. (default off)
   279  ```
   280  
   281  See the [global flags page](/flags/) for global options not listed here.
   282  
   283  ### SEE ALSO
   284  
   285  * [rclone serve](/commands/rclone_serve/)	 - Serve a remote over a protocol.
   286