I am connected to an sftp server using

sftp -i key.pem user@server

The server contains logs and I can list logs up to 4 days old using ls. The problem is that ls does not seem to be able to fetch than 4 day old logs. I am wondering how can I list all the logs in the directory and get their total size?

A similar question about the size has been asked here and provides a solution using du -hc. But this command does not exist on my sftp server neither I have ssh access. Any ideas?


1 Answer 1


lftp has a du command and does support the sftp protocol:

lftp sftp://user@host

Or to specify the ssh key to use and skip the password prompt:

lftp -e 'set sftp:connect-program ssh -axi key.pem' sftp://user:@host

And run du (or du -ba to list each file along with their size in bytes, or du -ha to use suffixes) at the sftp prompt. Note that it's different from the Unix du command in that it gives the apparent size as opposed to disk usage and doesn't include the size of directory files.

If ls doesn't list files older than 4 days, the most likely explanation is that they're not or no longer there. The ls command of the sftp or lftp client will just perform a "read directory" query or series of queries in the SFTP protocol to retrieve the directory contents. If the server doesn't send what's there and you don't have any way to access the data other than over SFTP, there's little else you can do.


You must log in to answer this question.

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