Python / FTPlib - 返回FTP传输的结果?

时间:2016-07-28 08:06:51

标签: python ftplib

我有一个将文件传输到FTP服务器的功能,是否可以存储会话结果?

以下代码:

 ....
 with tempfile.NamedTemporaryFile() as temp:
  temp.write(content)
  temp.seek(0)
  filename = temp.name
  session = ftplib.FTP('10.66.118.251','build','password')
  session.storbinary('STOR {0}'.format(file_name), temp)
  session.quit()
  temp.flush()

我已经尝试过以下方法来获得结果:

...  with tempfile.NamedTemporaryFile() as temp:
...   temp.write(content)
...   temp.seek(0)
...   filename = temp.name
...   session = ftplib.FTP('10.66.118.251','build','password')
...   session.storbinary('STOR {0}'.format(file_name), temp)
...   session.quit()
...   temp.flush()
...
'226 Transfer complete.'
'221 Goodbye.'
>>> print session
<ftplib.FTP instance at 0x3018098>
>>> print session.storbinary()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: storbinary() takes at least 3 arguments (1 given)
>>>

0 个答案:

没有答案