Python Paramiko deletes files on get or open
I am trying to use paramiko's SFTP module to read a file from a remote server but any time I call
sftp.get('remote_filename', 'local_destination') It deletes 'remote_filename' from the server. I also tried getting the file object directly using
sftp.file('remote_filename') but it still deletes the file after opening. Can anyone tell me why this might be happening? Here is an example function that takes a filename as parameter and returns the SFTP File object:
import paramiko, socks, os
def get_file(filename):
sock = socks.socksocket()
username = 'username'
key = paramiko.DSSKey.from_private_key_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'id_dsa'),
password=os.environ.get('PKEY_PASSWORD'))
host = 'myftpserver.com'
port = 22
# Connect to server
sock.connect((host, port))
transport = paramiko.Transport(sock)
transport.connect(username=username, pkey=key)
sftp = paramiko.SFTPClient.from_transport(transport)
return sftp.file(filename)
Thanks
Try this
import paramiko
import os
paramiko.util.log_to_file("C:DocsPersonalMovieslog.log")
host = "10.22.16.5"
port = 22
transport = paramiko.Transport((host, port))
# Auth
password = "whpee"
username = "root"
transport.connect(username = username, password = password)
# Go!
sftp = paramiko.SFTPClient.from_transport(transport)
# Download
localfile="C:DocsPersonalMoviestemp.txt"
remotefile="/root/temp.txt"
sftp.get(remotefile,localfile)
If its still deleting , lets check the log file
链接地址: http://www.djcxy.com/p/33644.html