如何使用php检查ssh服务器中的文件是否为空

I am connecting to a SSH server using PHP and there is file called difference in the server. I want to check whether it is empty or not and echo something depending on the result.

I am aware of the function :

file_get_contents("./difference")

But this will work in in the localhost directory. I want to check in the SSH server. How Should i proceed...?

PS : I use ssh2 to connect to ssh server

you can use this ways :

1) use ssh2.sftp protocol :

$data  = file_get_contents('ssh2.sftp://user:pass@youraddress.com:22/path/to/one/file');

2) use ssh2

$ssh2_conn = ssh2_connect('youraddress.com', 22);
ssh2_auth_password($ssh2_conn, 'username', 'password');
$sftp_conn = ssh2_sftp($ssh2_conn);
$file_stream = fopen("ssh2.sftp://$sftp_conn/path/to/one/file", 'r');

You could try:

if (0 == filesize($path_to_difference)){
echo "File is empty!";
} else {
echo "File has data inside!";
}

Is that what you're looking for?