Reputation: 149
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.
Upvotes: 7
Views: 25116
Reputation: 1
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 [email protected] << EOT ls -l | grep "filename" | awk '{print $5}' EOT)
Upvotes: 0
Reputation: 25966
You can get the file size of the remote files using the ls
command by passing parameters.
To get Size of the file pass ls -l
To get Size of the file (HIdden files included) ls -al
To get it in human readable format pass ls -lh
or ls -alh
Upvotes: 1
Reputation: 141
If you'd like the size output to be human readable, try: ls -lah
Upvotes: 12