1

I am trying to write a python script which uses scp to log into a HPC cluster (where I have an account) and transfer files from the cluster to my local system. I am able to os.system() to type the scp command. But, after that, I am a bit confused about what I must do when I am asked for the password (assume my password is password). I have tried os.system('password') and print 'password', but they don't work.

This is the python script that I have written:

import os
import sys

password = 'password'
clusterpath = 'myname@cluster.hpc1.cs.univ.edu:/Projects/re* '
localpath = 'Projects/.'
os.system('scp ' + clusterpath  + localpath)

When I execute this script, I am asked for the password of my cluster. How can I enter the password of the cluster account through this python script?

Commoner
  • 1,678
  • 3
  • 19
  • 34
  • 2
    Not really a Python answer for your question, but maybe you should be using the SSH key pair authentication, so that you just needed to `ssh-add` and type your SSH key password once, then run your script multiple times without being asked for it again. – hdiogenes May 14 '18 at 20:08
  • Possible duplicate of [How to make ssh receive the password from stdin](https://stackoverflow.com/questions/1340366/how-to-make-ssh-receive-the-password-from-stdin) – Davis Herring May 15 '18 at 01:29

0 Answers0