how to delete my file if exits in the remote server with paramiko?

Skip Montanaro skip.montanaro at gmail.com
Sun Dec 14 08:35:27 EST 2014


On Sun, Dec 14, 2014 at 6:49 AM, 水静流深 <1248283536 at qq.com> wrote:
> Is there more elegant way to do the same work?

Unlikely. You have two fairly simple bits of code in your example, one
to connect to the remote server, the other to check for the file's
existence and remove it. The only extra elegance I see is to isolate
those two bits of work into separate functions, so you execute
something like:

sftp = connect_via_paramiko("vps ip", 22)
remove_remote_file(sftp, "/home/names.txt")

Presumably, if you have other work to do on the server, you'd save the
sftp object for reuse.

Skip



More information about the Python-list mailing list