在我的程序中,我只是使用for循环将创建的文件上传到ftp服务器。 我上传成功但内容空洞。最奇怪的是,当我对文件名进行硬编码时,内容就在那里。但是当我使用参数名称上传函数时,我只得到空文件。
这是上传代码。
section_number
是for循环键。
if group == 1:
title_str = 'pri'
elif group == 2:
title_str = 'sec'
else:
title_str = 'all'
filename = '%s_section_s%d.json'%(title_str,section_number)
with open(filename, 'w') as outfile:
json.dump(dictData, outfile)
ftp.ftpUpload(filename, "dataFile/")
def ftpUpload(filename, filePath):
ftp = ftplib.FTP('203.xx.x.xxx', 'xxxx', 'xxxxx')
ftp.cwd(filePath) #changing to /pub/unix
'''filename = 'sec_section_s5.json';'''
ftp.storlines("STOR %s"%(filename), open(filename, 'rb'))
files = ftp.dir()
ftp.close()