次の3つの方法でディレクトリを変更しようとしましたが、変更されません。他の誰かがこの問題を抱えていましたか?
import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
host = 'server1.mydomain.com' # altered
with pysftp.Connection(host=host, **get_credentials(), cnopts=cnopts) as connection:
connection.execute('cd project')
print(connection.execute('pwd')) #---> [b'/home/jm\n']
connection.execute('cd /home/jm/project')
print(connection.execute('pwd')) #---> [b'/home/jm\n']
connection.cd('project')
print(connection.execute('pwd')) #---> [b'/home/jm\n']
with connection.cd('project'):
print(connection.execute('pwd')) #---> [b'/home/jm\n']
'/home/jm/project/'
ちなみに存在します。ここにリストしていない他の多くの組み合わせも試しました。
それは私には意味がありません、あなたは助けることができますか?
chdir()
代わりに試してください。ドキュメントによると:
cd(remotepath=None)
context manager that can change to a optionally specified remote directory and restores the old pwd on exit.
chdir(remotepath)
change the current working directory on the remote
そう:
connection.chdir('/home/jm/project')
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加