0
from ftplib import FTP
import socket

ftp = FTP('***.*.***.***') 
ftp.login(user='someusername',passwd='somepassword')
ftp.cwd('fcst') // this is a subfolder on the ftp.No error here
i=4
filename='C:\Users\user\Desktop\INTERNSHIP\SOLAR_DADRI\data.xlsx'
localfile=open(filename,'wb')
while(i<7):
        j=1
        while(j<10):
            fileName='dadfrcst0'+str(j)+'0'+str(i)+'r2.xlsx'
            j=j+1
            ftp.retrbinary('RETR '+fileName,localfile.write,1024)


        i=i+1
ftp.close()
localfile.close()

So i was trying to retrieve files from a FTP server and write them all down into one excel file. I want to essentially append as all the files have the same format and i want to do a timeseries analysis.

Also just so you know all the files on the server are in excel format are files in different dates as specified by the regular expression i used to retrieve..i.e 'dadrfcst0104r2.xlsx' implies 1st April's data.

So when i run the code it shows the file size to be big and when i open it it shows an error and then is showing only the 1st april data.. The loops are right. There is no error there. PLEASE HELP.

YNWA
  • 43
  • 7

1 Answers1

-1

isn't it possible to append file as a .txt one? Well, that's how I do in one of my scripts

import datetime

today = datetime.datetime.today()
f = open(today.strftime("/home/pi/%Y/%b/%d-%b-%Y.txt"), "a")  #Append mode
f.write(str(today.strftime("%d-%b-%Y, %H:%M,"))) #Date an hour of event
f.write(str(pressure)+",")
f.write(str(temperature)+",")
f.write(str(humidity)+",")
f.write(str(energy)+",")                      #CSV format
f.close() #Close file

After that, I just open the file and process it in excel to create a table. Not so professional, but just an opinion as a beginner

ElectroMESH
  • 1
  • 1
  • 6