我正在创建一个csv文件并将其上传到ftp服务器。 因此,上传包括该ftp服务器上多家公司的路径。
喜欢:
COMANY1 / FOO / BAR
但对于最后的一些公司,我得到了这个追溯:
Traceback (most recent call last):
File "exporter.py", line 117, in <module>
Exporter().run()
File "exporter.py", line 115, in run
self.upload(file, vendor['ftp_path'], filename)
File "exporter.py", line 78, in upload
sftp.chdir(dir)
File "/home/johndoe/exports/daily/venv/local/lib/python2.7/site-packages/paramiko/sftp_client.py", line 580, in chdir
if not stat.S_ISDIR(self.stat(path).st_mode):
File "/home/johndoe/exports/daily/venv/local/lib/python2.7/site-packages/paramiko/sftp_client.py", line 413, in stat
t, msg = self._request(CMD_STAT, path)
File "/home/johndoe/exports/daily/venv/local/lib/python2.7/site-packages/paramiko/sftp_client.py", line 730, in _request
return self._read_response(num)
File "/home/johndoe/exports/daily/venv/local/lib/python2.7/site-packages/paramiko/sftp_client.py", line 781, in _read_response
self._convert_status(msg)
File "/home/johndoe/exports/daily/venv/local/lib/python2.7/site-packages/paramiko/sftp_client.py", line 807, in _convert_status
raise IOError(errno.ENOENT, text)
IOError: [Errno 2] The requested file does not exist
我认为堆栈跟踪是指ftp路径,它不存在(但确实存在)。
但是当我尝试在那些完全相同的路径上运行该脚本(导致问题)时,它会通过吗?
所以,它不是一个逻辑错误,并且那些ftp路径确实存在 - 但它可能是由于某些超时发生了吗?
谢谢, 汤姆
更新
我这样称呼方法:
self.upload(file, vendor['ftp_path'], filename)
进行上传的实际方法:
def upload(self, buffer, ftp_dir, filename):
for dir in ftp_dir.split('/'):
if dir == '':
continue
sftp.chdir(dir)
with sftp.open(filename, 'w') as f:
f.write(buffer)
f.close()
sftp.close()