Sign up ×
Server Fault is a question and answer site for 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 (Linux machine red hat 5.3) and get from this Linux the file.txt , please advice?

  Password: password123
  cd /var/tmp
  get  file.txt 
  sftp> quit

  the full view from sftp command line

  Connecting to 
  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.

share|improve this answer

Fabric is great to do this work.

  1. install fabic, refs:

    pip install fabric
  2. create a 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 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


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.