问题
I need to implement sftp server using python. My requirement is to move the file from remote machine to my application using the sftp commands like
copy configurations sftp://<ipaddress>/<filename>
Is it possible to do with Paramiko. If so any code snippet or doc on how to accomplish it would be helpful.
回答1:
The following code snippet demonstrates simple implementation of sftp client with paramiko
>>> import paramiko
>>> pkey = paramiko.RSAKey.from_private_key_file('rsa.key')
>>> transport = paramiko.Transport(('localhost', 3373))
>>> transport.connect(username='username', password='password', pkey=pkey)
>>> sftp = paramiko.SFTPClient.from_transport(transport)
>>> sftp.listdir('.')
['File.txt', 'File2.txt']
Very simple SFTP server in python: sftpserver 0.2
来源:https://stackoverflow.com/questions/17290974/sftp-server-implementaion-with-python