Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question

3 Answers 3

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/

share|improve this answer

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.:)

share|improve this answer

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

share|improve this answer
    
The 'ssh' library on pypi is actually the latest version of Paramiko (renamed/forked). –  msanders Apr 5 '12 at 14:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.