someone please help!
im currently writting a python script to actually retrieve a file size that is in a local PC and a remote server. then, what i do is, i compare if the file's size are the same. below is my code :
A = "/path/of/the/file/in/my/local/PC"
B = "/path/of/the/file/in/remote/PC"
statinfo1 = os.stat(A)
statinfo2 = os.system ("ssh" " root@192.168.10.1" " stat -c%s "+B)
if statinfo1 == statinfo2 :
print 'awesome'
else :
break
problem encountered : statinfo1 is able to return the file size in the local PC, but statinfo2 is not able to return the file size.. anyone please help? i want to use SSH method
Using paramiko or pexpect will work, but may be kind of heavyweight for your simple use case here.
You can use a lightweight solution that simply relies on
ssh
of the underlying OS, and python builtinsubprocess
module.Why dont you use Paramiko SSHClient. Its a nifty third party library simplifying
ssh
access.So to check file size of remote file the code would be something like -
Check this too - How to get size of remote file? and SSH programming with Paramiko
What does
os.stat
return?what does
os.system
return?int
representing the exit code of the program invoked.So the comparison between them is bound to fail. Consider Paramiko as @Srikar suggests, or address the issues with this approach.
For the latter, try this:
You could also take a look at fabric for easy remote tasks.
fabfile.py:
Shell command: