user1086526
user1086526

Reputation: 93

Paramiko how to specify Folder path

import paramiko
import os
import sys

ssh = paramiko.SSHClient()
paramiko.util.log_to_file('U:\\Temp\\paramiko.log')
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())


ssh.connect('172.18.24.234','/TestBTEC/',22,'btectest','M3j0Stanf0rd')
stdin, stdout, stderr = ssh.exec_command("mkdir abc")
stdout.readlines()

This is obviously throwing back errors. What is the proper way to set the home directory on the remote server for user btectest

Upvotes: 1

Views: 3405

Answers (2)

shahjapan
shahjapan

Reputation: 14355

Instead of setting you can also specify parent directory as userprofile as below import os

abc_dir = os.path.join('%UserProfile%','abc')
cmd = "mkdir %s" % abc_dir
stdin, stdout, stderr = ssh.exec_command(cmd)

Upvotes: 1

Clark
Clark

Reputation: 376

The parameters you are passing to SSHCient.connect() are incorrect (at least for paramiko 1.6+). Your connect() call should look like this:

ssh.connect('172.18.24.234', username='btectest', password='...')

or if you explicitly include the port:

ssh.connect('172.18.24.234', 22, 'btectest', '...')

Once connected, you should already be in the home directory of the user "btectest", as can be seen with this:

stdin, stdout, stderr = ssh.exec_command("pwd")
stdout.readlines()

Upvotes: 0

Related Questions