python - Are paramiko file transfer operations atomic? -


i use get , put methods of paramiko.sftp object. can vaguely remember did @ times incomplete file contents get method, never noticed issue put. luck, or should perform checks ensure right files on remote side? if so, how do it, given have sftp access remote server?

by sftp-only access, mean cannot ssh in:

$ ssh user@ipaddress user@ipaddress's password:  pty allocation request failed on channel 0 shell request failed on channel 0 

you can if sftp transfer completed without error or interruption, file has been copied over, since sftp protocol requires each chunk sent acknowledged. so, between reliability of tcp, ssh channel, , acks each chunk, it's unlikely file has been truncated in way.

a couple more things when using sftp:

  • after transfer, can call stat() on file verify it's actual size.
  • you read 1 or more chunks of file , compare them locally.
  • some sftp servers have check-file extension (i don't think openssh supports though). paramiko sftp files have check() method allows hash of or of file.

and directly answer question's title, transfers not atomic. file still altered on system it's being written. if want prevent against that, write file temporary location remotely, verify it, call sftp.rename move it's final destination (which atomic operation on linux within same filesystem). that's analogous rsync does, , close can come "atomic".


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -