I am using Paramiko to send an ssh command to a remote Windows Server, which works, BUT I need to set an environment variable first which sets a password for the main command to use. So on the Windows Server command line I use:
$ set ASPERA_SCP_PASS=passwordToUse
$ ascp -d --src-base=//DirectoryToSend //DirectoryToSend [email protected]:/
This sets an environment variable passwordToUse which gets used in the ascp command.
But I can't get this working with Paramiko. When running the below script I get exit status: 0, but the command does not run on the remote server.
import sys
import paramiko
nbytes = 4096
hostname = '10.0.0.1'
port = 22
username = 'remoteUsername'
password = 'remotePassword'
command1 = 'set ASPERA_SCP_PASS={}'.format('passwordToUse')
command2 = 'ascp -d --src-base=//DirectoryToSend //DirectoryToSend [email protected]:/'
command3 = command1 + ", " + command2
client = paramiko.Transport((hostname, port))
client.connect(username=username, password=password)
stdout_data = []
stderr_data = []
session = client.open_channel(kind='session')
session.exec_command(command3)
while True:
if session.recv_ready():
stdout_data.append(session.recv(nbytes))
if session.recv_stderr_ready():
stderr_data.append(session.recv_stderr(nbytes))
if session.exit_status_ready():
break
print 'exit status: ', session.recv_exit_status()
print ''.join(stdout_data)
print ''.join(stderr_data)
session.close()
client.close()
something like this?
command1 = 'set ASPERA_SCP_PASS={}'.format(os.environ['ASPERA_SCP_PASS'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With