Get the remote server file size in UNIX

Hi All,

I am trying to sftp, get a file from remote server.
Post this we need to check the remote server file size or checksum value of the remote server file and compare it with the file size in the current server.

But I am facing issue to get the remote server file size. Could you please help me on this.
System: Sun OS 5.10
I have tried below approaches but is not working out:

1)

 sftp user@hostname << EOF
ls -l filename > filesize.txt
get filesize.txt
EOF

Gives error as couldn't stat remote file: No such file or directory

2)

ssh user@hostname "ls -l filename"

Doesn't give output as the unix prompt doesn't come back and need to kill the connection.

Could you please help me on this.

Thanks

---------- Post updated at 11:48 AM ---------- Previous update was at 09:41 AM ----------

I have resolved using below:

sftp user@hostname << EOF>/path/remote_size.txt
ls -l filename
EOF

Thanks for letting us know you solved by yourself and mostly, gave your solution :b:

Why do you need to compare file sizes? I'd be surprised if sftd didn't reflect a failure in its exit code.