The first is to capture an image from the camera:
Copy the Code code as follows:
While 1: #测试摄像头的存在
Try
Cam = Device ()
Except
Print "No webcam found!"
Continue
Break
Then upload the image to the FTP server:
Copy the Code code as follows:
Remote = Ftplib. FTP (' 127.0.0.1 ') #登陆服务器
Remote.login ()
File = open ('%s.jpg '%cur_time, ' RB ') #用时间来命名图片
Remote.storbinary (' STOR%s.jpg '%cur_time,file) #上传图片
File.close ()
Of course, finally, delete the picture.
Here are the programs that upload images from the camera to the native FTP every second:
Copy the Code code as follows:
Remote = Ftplib. FTP (' 219.246.57.162 ')
Remote.login ()
While 1:
Try
Remote.nlst ("1.txt")
Except
Print "Not ready to start!"
Continue
Timex = Time.localtime ()
Cur_time = "%4d%02d%02d%02d%02d%02d"% (Timex[0],timex[1],timex[2],timex[3],timex[4],timex[5])
Cam.savesnapshot ('%s.jpg '%cur_time)
#remote. Dir ()
File = open ('%s.jpg '%cur_time, ' RB ')
Remote.storbinary (' STOR%s.jpg '%cur_time,file)
File.close ()
Os.system ("del%s.jpg"%cur_time)
#print "Upload ok!"
Time.sleep (1)
Remote.quit ()