I have this in crontab:
*/6 * * * * python3 /root/projects/download.py >> /root/projects/download_errors.log 2>&1
*/10 * * * * python3 /root/projects/upload.py >> /root/projects/upload_errors.log 2>&1
which run fine (every 5 minutes and every 10 minutes)
Basically my download script downloads a file from a FTP server and the upload script uploads it to different FTP servers. Thing is, both scripts run fine 2 or 3 times, then suddenly the downloaded file becomes 0 KB (on the FTP server it is not 0 KB). Which is funny because I have this in my download script:
if ftp.size('file.txt') > 0:
grabFile()
else:
print("%s The file has 0 KBs..." % date)
Code snippets:
Download script:
def grabFile():
filename = 'file.txt'
localfile = open(filename, 'wb')
ftp.retrbinary('RETR ' + filename, localfile.write, 1024)
ftp.quit()
localfile.close()
(everything else is the login part and initiating the ftplib)
Upload one:
my_file = "/root/projects/file.txt"
file = open(my_file,'rb')
session = ftplib.FTP()
session.connect(host='my_hostname', port=21)
session.login('my_username', 'my_password')
session.cwd('/path/to/the/file')
session.storbinary('STOR '+ 'file.txt', file)
session.quit()
file.close()
The output files are empty.