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

Matthew_WARREN at bnpparibas.com Matthew_WARREN at bnpparibas.com
Tue Feb 5 12:14:19 EST 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.


Matt.




                                                                                                                                 
           Internet                                                                                                              
           charles_hans at yahoo.com                                                                                                
                                                                                                                              To 
                                                                        python-list                                              
           Sent by:                                                                                                           cc 
           python-list-bounces+matthew.warren=uk.bnpparibas.com@                                                                 
           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()
    chan.exec_command(command)
    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
tried
to type the full path in 'cd', did not help. Other UNIX commands such as
ls,
mkdir, cp, rm will work. Only this 'cd' never works. I got stuck here.

Please help. Thanks!

Charles
2/2
--
View this message in context:
http://www.nabble.com/Why-chdir-command-doesn%27t-work-with-client.get_transport%28%29---tp15248798p15248798.html

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

--
http://mail.python.org/mailman/listinfo/python-list



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