通过python sftp +自动sftp

有可能通过python运行以下步骤?

我的目标是通过python自动化sftp – login到13.5.41.90(Linux机器红帽5.3)并从这个Linux获得file.txt,请指教?

sftp 13.5.41.90 Password: password123 cd /var/tmp get file.txt sftp> quit the full view from sftp command line sftp 13.5.41.90 Connecting to 13.5.41.90... Password: password123 sftp> cd /var/tmp sftp> get file.txt Fetching /var/tmp/file.txt to info.txt /var/tmp/file.txt 100% 340 0.3KB/s 00:00 sftp> quit 

织物是伟大的做这项工作。

  1. 安装fabic,参考: http : //fabfile.org/

     pip install fabric 
  2. 创build一个fabfile.py,如下所示:

     from fabric.api import * from fabric.operations import put from fabric.operations import get env.user = "username" env.password = "password123" def do(): put(local_path="./temp/file.txt", remote_path="/tmp/file.txt") get(remote_path="/tmp/file.txt", local_path="./temp/file.txt") 
  3. 运行

      fab do 

应该pipe用。:)

查看Python的Paramiko库。 我已经使用它的SSH,但我知道它也有一个SFTP对象的实现。

http://www.lag.net/paramiko/

检查pypi存储库 。 我build议你使用http://pypi.python.org/pypi/ssh/1.7.9 。 它用在织物上