Environment Variable Differences When Using Paramiko

Environment variable differences when using Paramiko

Working with the Channel object instead of the SSHClient object solved my problem.

chan=ssh.invoke_shell()
chan.send('echo $PATH\n')
print (chan.recv(1024))

For more details, see the documentation

Use environment variable in SFTP path in Paramiko

You cannot use environment variables in SFTP. You have to use real paths. In this case the real path is /opt/CPsuite-R80/fw1.

If the real path is not fixed, and you really need to obtain the real path from a variable value, you will need to resolve the variable value using a different interface (e.g. using a shell access). And then use the resolved value in SFTP. This is what you do in WinSCP - you execute cd $FWDIR in the shell. And the shell resolves $FWDIR to /opt/CPsuite-R80/fw1. In Paramiko, you can use SSHClient.exec_command to resolve the variable:

stdin, stdout, stderr = ssh.exec_command("echo $FWDIR")
fwdir = stdin.read()

Python - using env variables of remote host with / SSH

ssh.exec_command doesn't interpret the remote .profile. Try this:

ssh.exec_command('. .profile ; cd /home/test/;$run ./test.sh')


Related Topics



Leave a reply



Submit