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
Function Not Changing Global Variable
Recursion and Return Statements
Is There a Decorator to Simply Cache Function Return Values
Automatically Create Requirements.Txt
Typeerror: Not All Arguments Converted During String Formatting Python
Python Setup.Py Develop VS Install
Pip Install Access Denied on Windows
Passing Functions with Arguments to Another Function in Python
Merge Lists That Share Common Elements
Polling the Keyboard (Detect a Keypress) in Python
How to Find Length of Digits in an Integer
Testing Whether a Numpy Array Contains a Given Row
Sftp in Python? (Platform Independent)
Performance of Pandas Apply VS Np.Vectorize to Create New Column from Existing Columns
Is Shared Readonly Data Copied to Different Processes for Multiprocessing