Get size of file on remote server

Viewed 15835

I have a requirement where I need to do SFTP connection to remote server, get the size of the file on remote server and depending on the size, i need to get the file onto local server. Is there any command in SFTP to get the size of the file.

3 Answers

you can get the size using James's with awk

ls -l | grep "filename" | awk '{print $5}'

If you are using it in a script and want to check using logic, you can store the file size in a variable like so.

varname=$(ls -l | grep "filename" | awk '{print $5}')

Then call sftp and the task

For a remote file maybe do this

filesize=$(ssh user@domain.ex << EOT ls -l | grep "filename" | awk '{print $5}' EOT)
Related