Why chdir command doesn't work with client.get_transport() ?

Matthew_WARREN at bnpparibas.com Matthew_WARREN at bnpparibas.com
Tue Feb 5 18:14:19 CET 2008

As other have said, it's because exec_command uses a new session each time.

You may get some joy with this, untested

exec_command('cd /some/where; somecommand')

uses the semi-colon to separate multiple commands on one command line.


           charles_hans at yahoo.com                                                                                                
           Sent by:                                                                                                           cc 
           python.org                                                                                                    Subject 
                                                                        Why chdir command doesn't work with                      
           02/02/2008 23:41                                             client.get_transport() ?                                 

I am new to paramiko. I wrote a script to copy files between Solaris and XP
machines as below:

import paramiko
def exec_command(trans, command):
    chan = trans.open_session()
    stdin = chan.makefile('wb')
    stdout = chan.makefile('rb')
    stderr = chan.makefile_stderr('rb')
    return stdin, stdout, stderr
def main():
    client = paramiko.SSHClient()
    client.connect(hostname, username=username, password=password)
    trans = client.get_transport()
    dummy_chan = trans.open_session()
    exec_command(trans, 'cd temp')
    stdin, stdout, stderr = exec_command(pwd)

>From the last line I found from stdout that the pwd is not changed. I
to type the full path in 'cd', did not help. Other UNIX commands such as
mkdir, cp, rm will work. Only this 'cd' never works. I got stuck here.

Please help. Thanks!

View this message in context:

Sent from the Python - python-list mailing list archive at Nabble.com.


This message and any attachments (the "message") is
intended solely for the addressees and is confidential. 
If you receive this message in error, please delete it and 
immediately notify the sender. Any use not in accord with 
its purpose, any dissemination or disclosure, either whole 
or partial, is prohibited except formal approval. The internet
can not guarantee the integrity of this message. 
BNP PARIBAS (and its subsidiaries) shall (will) not 
therefore be liable for the message if modified. 
Do not print this message unless it is necessary,
consider the environment.


Ce message et toutes les pieces jointes (ci-apres le 
"message") sont etablis a l'intention exclusive de ses 
destinataires et sont confidentiels. Si vous recevez ce 
message par erreur, merci de le detruire et d'en avertir 
immediatement l'expediteur. Toute utilisation de ce 
message non conforme a sa destination, toute diffusion 
ou toute publication, totale ou partielle, est interdite, sauf 
autorisation expresse. L'internet ne permettant pas 
d'assurer l'integrite de ce message, BNP PARIBAS (et ses
filiales) decline(nt) toute responsabilite au titre de ce 
message, dans l'hypothese ou il aurait ete modifie.
N'imprimez ce message que si necessaire,
pensez a l'environnement.

More information about the Python-list mailing list