Python timed acquisition camera Image Upload ftp server function implementation

Source: Internet
Author: User

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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.