0
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
client.connect('example.com',22,'XXXXX','XXXX')
a=input ("enter the file path")
stdin,stdout,stderr=client.exec_command('cd a && pwd')

I want to pass the variable 'a' to the exec_command .. I am trying to get the file path from the user and i am storing it in a variable a, i want to know how i can pass the variable a to the Cd command under exec_command function

0

2 Answers 2

1

Since there can be some security flaws by code injection, you must not format user input directly into shell commands.

Here you can use environment variables:

stdin,stdout,stderr=client.exec_command('cd "$a" && pwd', environment={'a': a})
Sign up to request clarification or add additional context in comments.

Comments

0

Did you try constructing the command from the variable?

stdin,stdout,stderr=client.exec_command('cd ' + str(a) + '&& pwd')

2 Comments

thnks .. Let me try that
This has the potential to be incredibly dangerous.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.