1

is it possible to run the following steps via python?

my target is to automated sftp by python - login to 13.5.41.90 (Linux machine red hat 5.3) and get from this Linux the file.txt , please advice?

  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

3 Answers 3

2

Fabric is great to do this work.

  1. install fabic, refs: http://fabfile.org/

    pip install fabric
    
  2. create a fabfile.py as below:

    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. run with

     fab do
    

Should work.:)

1

Check out the Paramiko library for Python. I've used it for SSH, but I know it does have an SFTP object implementation as well.

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

0

check out pypi repository. I suggest you to use http://pypi.python.org/pypi/ssh/1.7.9. It used in the fabric

1
  • The 'ssh' library on pypi is actually the latest version of Paramiko (renamed/forked).
    – msanders
    Apr 5, 2012 at 14:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .