python sftp传输文件总是报文件不存在_Jsch sftp异常:找不到文件(即使文件存在)...

我正在编写一个jython代码,它使用Jsch在远程机器上运行一些shell指令。在继续在本地计算机上执行jython代码之前,我需要等待特定的shell指令完成(=需要在远程计算机上同步shell代码)。在

为此,当特定的shell指令完成后,我在远程机器中创建一个文本文件。然后在我的jython代码中,我打开一个sftp通道并定期尝试获取该文件(使用sftp.异常以及“while true”循环)。代码等待文件下载。在

我的问题是,即使文件被创建,jsch函数“get”也无法下载文件并继续发送sftp.异常:没有这样的文件或目录“。这使我被锁在一个无限循环中。在

这是我的代码:#We generate the info files for each class of the classlist

for classname in classlist:

print ("Generating information file (format : .out) for the class %s " % (classname))

#We open a shell channel and run the commands "windchill shell" and then "InfoReport.sh classname".

channel_generate = gl_session.openChannel('shell')

ops = channel_generate.getOutputStream()

ps = PrintStream(ops, True)

channel_generate.connect()

ps.println("windchill shell")

ps.println('rm ' + self.wt_home + '/tmp/' + classname + '.txt')

#The following instruction is the one i need to synchronize

ps.println(self.wt_home + '/bin/' + self.command + " " + classname)

#I create a file to detect the end of the previous instruction

ps.println('echo ok > ' + self.wt_home + '/tmp/' + classname)

ps.println('exit')

ps.close()

#Here we wait until the synchro file is created.

#We connect an sftp server and test every 4 seconds if we can retrieve the file.

channel_synchro = gl_session.openChannel('ftp')

channel_synchro.connect()

#This loop is broken when the get is successful

while True:

try:

channel_synchro.get(self.wt_home + '/tmp/' + classname,'/home/dev/temp')

break

except jsch.SftpException:

time.sleep(4)

#Disconnect and close de sftp channel

channel_synchro.disconnect()

channel_synchro.close()

#Disconnect and close the shell channel

channel_generate.disconnect()

channel_generate.close()

我尝试过不同的解决方案:其他类型的循环,在“while true”循环的每次迭代中创建一个新通道,我考虑过用户权限问题,我检查了路径是否准确,是否正确,我检查了我的机器的sftp功能是否正常工作。

什么都不管用,我还是解决不了这个问题

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值