First, capture an image from the camera:
Copy codeThe Code is as follows:
While 1: # test the existence of the camera
Try:
Cam = Device ()
Except t:
Print "no webcam found! "
Continue
Break
Then upload the image to the ftp server:
Copy codeThe Code is as follows:
Remote = ftplib. FTP ('127. 0.0.1 ') # log on to the server
Remote. login ()
File = open('{s.jpg '% cur_time, 'rb') # name the image by Time
Remote. storbinary ('stor upload s.jpg '% cur_time, file) # upload an image
File. close ()
Of course, delete the image.
The following is a program that uploads images collected from the camera to the ftp server every second:
Copy codeThe Code is as follows:
<Span style = "font-family:, Arial; line-height: 15px; background-color: rgb (245,247,248 ); "> </span> <pre name =" code "class =" python "> remote = ftplib. FTP ('2017. 246.57.162 ')
Remote. login ()
While 1:
Try:
Remote. nlst ("1.txt ")
Except t:
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 2.16s.jpg '% cur_time, file)
File. close ()
OS. system ("del mirrors.jpg" % cur_time)
# Print "upload OK! "
Time. sleep (1)
Remote. quit () </pre> <br>
<Pre> </pre>
<P> </p>
<Pre> </pre>
<P> </p>