次のコードがあるとします。
class sshConnection():
def getConnection(self,IP,USN,PSW):
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(IP,username=USN, password=PSW)
channel = client.invoke_shell()
t = channel.makefile('wb')
stdout = channel.makefile('rb')
print t //The important lines
return t //The important lines
except:
return -1
myConnection=sshConnection().getConnection("xx.xx.xx.xx","su","123456")
print myConnection
結果:
<paramiko.ChannelFile from <paramiko.Channel 1 (open) window=1000 -> <paramiko.Transport at 0xfcc990L (cipher aes128-ctr, 128 bits) (active; 1 open channel(s))>>>
<paramiko.ChannelFile from <paramiko.Channel 1 (closed) -> <paramiko.Transport at 0xfcc930L (unconnected)>>>
つまり、クラスメソッド内ではt
接続が接続されていますが、この接続記述子を返した後、接続が失われます。
それはなぜですか、どうすればそれを機能させることができますか?
ありがとう!