3

I would like to get the size of a remote directory using SFTP. Locally I would run du -sh, but my OpenSSH sftp client does not have that option. I would like to point out that I do not have SSH shell access, so any connections with ssh user@server will be dropped.

Any ideas? Maybe scripting a solution? For example I could imagine listing all remote files using ls -l in my SFTP session, but I would have to parse the output and traverse through all subdirectories. I am also open to using a different client than OpenSSH.

Both server and client are running Linux.

0

1 Answer 1

6

SSHFS uses the SFTP subsystem. This is a FUSE-based solution, get familiar with security concerns. You can (and should) do the mounting as a normal user:

sshfs user@server:some/path /some/local/mountpoint/

Then use du -sh locally. If the path of the directory you want is some/path/foo/directory on the remote system, then you need to use /some/local/mountpoint/foo/directory:

du -sh /some/local/mountpoint/foo/directory

To unmount:

fusermount -u /some/local/mountpoint/

Note: In the above example some/path is a relative path, relative to whatever remote directory SFTP initially uses as ./ for you. The string ./ itself (or . or an empty string) can be used to mount this exact directory. An absolute path can be used as well (e.g. /bar/baz/dir).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .