Note that there are some explanatory texts on larger screens.

plurals
  1. POSecure Copy File from remote server via scp and os module in Python
    primarykey
    data
    text
    <p>I'm pretty new to Python and programming. I'm trying to copy a file between two computers via a python script. However the code</p> <pre><code>os.system("ssh " + hostname + " scp " + filepath + " " + user + "@" + localhost + ":" cwd) </code></pre> <p>won't work. I think it needs a password, as descriped in <a href="https://stackoverflow.com/questions/68335/how-do-i-copy-a-file-to-a-remote-server-in-python-using-scp-or-ssh">How to copy a file to a remote server in Python using SCP or SSH?</a>. I didn't get any error logs, the file just won't show in my current working directory.</p> <p>However every other command with <code>os.system("ssh " + hostname + "command")</code> or <code>os.popen("ssh " + hostname + "command")</code> does work. -> <code>command = e.g. ls</code></p> <p>When I try <code>ssh hostname scp file user@local:directory</code> in the commandline it works without entering a password.</p> <p>I tried to combine <code>os.popen</code> commands with getpass and pxssh module to establish a ssh connection to the remote server and use it to send commands directly (I only tested it for an easy command):</p> <pre><code>import pxssh import getpass ssh = pxssh.pxssh() ssh.force_password = True hostname = raw_input("Hostname: ") user = raw_input("Username: ") password = getpass.getpass("Password: ") ssh.login(hostname, user, password) test = os.popen("hostname") print test </code></pre> <p>But I'm not able to put commands through to the remote server (<code>print test</code> shows, that hostname = local and not the remote server), however I'm sure, the conection is established. I thought it would be easier to establish a connection than always use <code>"ssh " + hostname</code> in the bash commands. I also tried some of the workarounds in <a href="https://stackoverflow.com/questions/68335/how-do-i-copy-a-file-to-a-remote-server-in-python-using-scp-or-ssh">How to copy a file to a remote server in Python using SCP or SSH?</a>, but I must admit due to lack of expirience I didn't get them to work.</p> <p>Thanks a lot for helping me.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload