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

水静流深 1248283536 at qq.com
Sun Dec 14 07:49:56 EST 2014


I want to delete the file "names.txt" if it exits in "/home/names.txt" in my remote vps server.
 import paramiko
host = "vps ip"
port = 22
transport = paramiko.Transport((host, port))
password = "key"
username = "root"
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
if "names.txt" in sftp.listdir("/home") : sftp.remove("/home/names.txt")
  
  
 Is there more elegant way to do the same work?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141214/dfd18a51/attachment.html>


More information about the Python-list mailing list