现在我需要打开一个远程文件来写东西,代码是这样的:
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(myHost,myPort,myUser,myPassword)
sftp = client.open_sftp()
fileObject = sftp.open(fullFilePath,'wb')
for i in xrange(10000):
fileObject.write(databuf)
fileObject.close()
现在我想确保所有数据都实际写入磁盘,因此代码修改如下:
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(myHost,myPort,myUser,myPassword)
sftp = client.open_sftp()
fileObject = sftp.open(fullFilePath,'wb')
for i in xrange(10000):
fileObject.write(databuf)
fileObject.flush()
os.fsync(fileObject.fileno())
fileObject.close()
但显示消息:
AttributeError: 'SFTPFile' object has no attribute 'fileno'
如果我想强制将文件同步写入磁盘,我该怎么办?