from datetime import datetime
from ftplib import FTP_TLS
from time import sleep
import time
import subprocess
import picamera
pic = 1
camera = picamera.PiCamera()
camera.resolution = (680, 480)
camera.rotation = 180
while True:
    now = datetime.now()
    now = str(now)
    now =now[0:10] + '_' + now[11:13] + '_' + now[14:16] + '_' + now[17:19]
    print(now)
    now = str(now)
    #camera.start_preview()
    #sleep(2)
    camera.capture( '/home/pi/PHOTO/' + now + '.jpg')
    #camera.stop_preview()
    print('photo taken')      
    s = FTP_TLS ('ftp.lafavre.us')
    s.login ('gear@lafavre.us', 'Iotisnumber1!')
    s.prot_p()
    filename = '/home/pi/PHOTO/' + now + '.jpg'
    ftppath = '/Aidan'
    s.cwd (ftppath)
    f= open (filename, 'rb')
    s.storbinary('STOR '+ now + '.jpg', f)
    print('donemydude')
    sleep(8)
    
