Can I get disk avail/used space using SFTP Client?

0 votes
asked Sep 27 by lanopk (450 points)

I want to get available and used disk space of sftp server.
I can not found related api on Rebex Sftp Client.
WinSCP shows disk space informations most of sftp servers.
How can I do?

Applies to: Rebex SFTP

1 Answer

+1 vote
answered Sep 27 by Lukas Matyska (39,480 points)
selected Sep 28 by lanopk
 
Best answer

This feature is not part of SFTP protocol, but there are several common extensions for it. We will add support for this feature to one of the next releases of Rebex SFTP.

But until that release is available: Many SFTP servers make it possible to execute remote commands or start remote shell. You can use it to execute appropriate command from the client.

For example, if the SFTP server runs on Unix system, you can execute 'df' command to get disk info.

How to do this with Rebex SFTP component is described here.

However, you can use Rebex Terminal Emulation component to do it simply like this:

// initialize SFTP object
Sftp client = new Sftp();
client.Connect(...);
client.Login(...);

// use SFTP commands
var items = client.GetList();
foreach (var item in items)
{
    Console.WriteLine("{1}\t{2}\t{0}", item.Path, item.Type, item.Length);
}

// initialize SSH object (from SFTP session)
var ssh = new Ssh();
ssh.Bind(client.Session);

// execute SSH remote commands
var response = ssh.RunCommand("df");
Console.WriteLine(response);
commented Sep 27 by lanopk (450 points)
Thank you very much.

I am already using 'df' command.
But some servers does not support this. (synology nas device,...)
So, Can I get your advice to implement SSH_FXP_EXTENDED function or statvfs@openssh.com extension using Rebex SFTP Client?
commented Sep 27 by Lukas Pokorny (85,590 points)
Sorry for having to do the research for us! I'll edit our reply. We can add support for both "statvfs@openssh.com" (already widely supported) and for "space-available" (an alternative extension supported by server vendors who - unlike OpenSSH - choose to follow the SFTP v6 draft).
commented Sep 27 by Lukas Pokorny (85,590 points)
edited Sep 27 by Lukas Pokorny
Please e-mail us your licensing info to support@rebex.net, we'll send you a link to a beta when it's available.
...