Automate FTP of screen captures

Dear Members,
I am working on a system which displays real-time images grabbed from a line sensor. Each grabbed image is displayed on the screen using a simple photon application developed by me. Everything works fine till here.

There is a new feature addition to be done to the above mentioned system. It is capturing the screen shots of the full screen photon application and sending the captured image to a FTP server automatically.
I am using PxWriteImage() function to save the screen-capture in jpeg format. (Please see … 293_1.html for more information)
After the screen-capture file is saved to local hard disk, I want it to transfer to another machine using FTP.
For this I have written following shell script and I invoke it through system() command passing the filename as argument 1 ( $1 )

ftp -n -i $SERVER <<SCRIPT
user $USER $PWD
mput $1

The above design works for few iterations and later the entire system is stalled.
I have checked with FTP server machine… only few files are transmitted.

Can you guide me what could be the possible reason for stalling of the system?


What happens if you save the next image to your-pic.jpg while you try to upload your-pic.jpg?
Have you tried implementing a minimum ftp-transfer into your sourcecode?
The script itself seems to be ok as far as i can see.

Alternate you could use this syntax:

ftp -u ftp://AjitG:ABC@ /root/personal/jpeg/your-pic.jpg

so its ftp -u ftp://[user[:pass]@]host:port[path] file

This won´t need a script at all.

Thannks Micro.

The answer for your question is -
The GUI is blocked temporarily when I try to save the next image to pic.jpg while I try to upload the recently saved image.

I think - it is typical Producer/Consumer problem.
The Screen Image Captures are generated at a faster rate than the FTP thread can consume.
The FTP thread is slow and hence it is blocking the GUI temporarily.

Now, to cut off the dependency between Image Capture thread and FTP thread, I have designed following strategy-
Let the Image Capture thread generate the real-time screen captures and save it in a local directory say “DIR” continuously.
The FTP tread is invokded at every 10 Sec to look for files in “DIR” nad transfer the files in bulk using “mput *” and later move the files to a backup directory from DIR so that new files can be written to the DIR by Image capature thread.

I am using pthread_sleepon_lock() and pthread_sleepon_unlock() for the synchronization of Image capture and FTP thread.
The sample implementation of this design is working fine. Now, I need to integrate it with my actual system code.

all suggestions are welcome… :slight_smile: