我正在尝试使用python从FTP下载文件。我能够成功进入目录但无法下载该文件。
我使用的命令是ftp.retrbinary('master.idx', open(fname,'wb').write)
错误如下。看起来该命令正在寻找MASTER.IDX
而不是master.idx
我要下载的文件的完整路径是ftp://ftp.sec.gov/edgar/full-index/2011/QTR2/master.idx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/ftplib.py", line 406, in retrbinary
conn = self.transfercmd(cmd, rest)
File "/usr/lib/python2.7/ftplib.py", line 368, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/usr/lib/python2.7/ftplib.py", line 331, in ntransfercmd
resp = self.sendcmd(cmd)
File "/usr/lib/python2.7/ftplib.py", line 244, in sendcmd
return self.getresp()
File "/usr/lib/python2.7/ftplib.py", line 219, in getresp
raise error_perm, resp
ftplib.error_perm: 500 MASTER.IDX not understood
答案 0 :(得分:2)
我不能说为什么名称会变为大写。在任何情况下,当使用FTP时,我这样做,它可能会帮助你:
server = "URL.of.server"
directory = "directory/where/the/file/is"
filename = "nameoffile.txt"
from ftplib import FTP
ftp = FTP(server) #Set server address
ftp.login() # Connect to server
ftp.cwd(directory) # Move to the desired folder in server
ftp.retrbinary('RETR ' + filename,open(filename, 'wb').write) # Download file from server
ftp.close() # Close connection
我认为它可能是'RETR',如果你不写,服务器可能无法理解你想做什么
答案 1 :(得分:1)
改用python的select date_format(event_time, 'yyyy-MM') as Month,
sum(price) as Monthly_Revenue
from oct_data_new
group by date_format(event_time, 'yyyy-MM')
order by Month;
模块。这是一个示例片段
wget