SSHLibrary.Put File 报错“IOError: Failure”

使用python完成本地文件上传至远程LINUX主机的功能,主要程序如下:

sftp.put(os.path.join('C:\\context\\test', 'test.txt'), os.path.join('/home/test', 'test.txt'))
在运行此程序时,提示SSHLibrary.Put File 报错“IOError: Failure”,使用print函数,把“
os.path.join('C:\\context\\test', 'test.txt')
”和“
os.path.join('/home/test', 'test.txt')

”的运行结果打印出来,发现join函数在Windows机器上运行时,会把"/home/test"和"test.txt"拼接成"/home/test\test.txt",从而导致报错。

解决方案:

1、升级SSHLibrary库至最新,升级方法参考我的一篇博文“python类库安装方法”;

2、为避免因环境不同而造成join生成的路径符号不同,不用join方法,直接把"/home/test"写成"/home/test/"、把"C:\\context\\test"写成"C:\\context\\test\\"。

你可能感兴趣的:(Python)