1

I am working on a project for which I'm using 30 Raspberry Pi (B) camera modules in the same network. I can take pictures from all of these simultaneously and now I want to copy these pictures from all Pi's to my local machine for further processing. I have used pscp and pslurp commands for this purpose but it returns me with error: Exited with error code 1. I used the commands like as follow;

$ pscp -h hosts.txt ~/camera/*.jpg ~/camera/*.jpg

$ pslurp -h hosts.txt -v -L ~/camera/1.jpg 2.jpg

Where hosts.txt is a file in which I have saved IP addresses of all remote machines and one camera directory is in the remote machine contains 1.jpg and later directory is in local machine. I have made public key and already saved in all remote machines so I don't need to give password flag in command. I use -v flag for verbose but it doesn't display me any information regarding error.

Any help will be much appreciated. Thanks in advance.

3
  • Are you copying the file from Raspberry pi to windows. Give the command like this pscp <host_ipaddress>: ~/camera/*.jpg ~/camera/*.jpg. If you are trying between Raspberry pi to linux why don't you use normal scp. Looks like you have to write a loop and iterate over the ipaddr on the hosts.txt file and execute the pscp for each. That should work
    – Varad A G
    Commented Sep 8, 2016 at 4:26
  • @VaradAG I have to copy file from raspberry pi to linux and I am finding a simple way to do it. Can you help me please in script or can you give me basic idea how the script will work.
    – jHz
    Commented Sep 8, 2016 at 6:18
  • You might want to have a look at my compoundpi project - it does more or less what you describe out of the can (controls multiple Pis with camera modules and handles transferring the resulting captures to a central client)
    – Dave Jones
    Commented Sep 8, 2016 at 20:17

3 Answers 3

1

Just built this script - you can use use it with list of raspberry pi.

Prerequisite -

  • You will need sshpass, you can install using $sudo apt-get install sshpass
  • You will need to create a file with following entry for each raspberry pi

    ip_address password

File should look like this hostname.txt

192.168.1.1 raspberry
192.168.1.2 raspberry

Once you create this file just save the following snippet with whatever name you like e.g. raspberry_sync.sh

#!/bin/bash

filename="$1"

download_and_delete(){
  ip_address=$1
  password=$2
  sshpass -p "$password" scp "pi@$ip_address:~/camera/*" .
  sshpass -p "$password" ssh "pi@$ip_address" "rm ~/camera/*"
}

while read -r line
do
  (download_and_delete $line)&
done < "$filename"

Once you save the script raspberry_sync.sh you can run it with parameter hostname.txt

  • Give execute access to file $chmod +x raspberry_sync.sh
  • Runt the script with hostname.txt as param ./raspberry_sync.sh hostname.txt

Happy Coding!! Cheers!!

3
  • Thank you! it worked for me but the copying process is taking too long. It took almost 10 mins for copying 30 pictures (3MB each) from remote machines. Is there any way to fast the process. One more thing I also want to delete pictures after copying from the remote machines? Thank you!
    – jHz
    Commented Sep 9, 2016 at 2:56
  • I have updated the shell script, please have a look at it. It will do two things 1. Download the files 2. Cleanup the files on remote machine. It will be more faster as it will fork a new process for each Raspberry Pi. Cheers!!
    – Tanuj
    Commented Sep 9, 2016 at 6:59
  • Thank you very much! Now it is working perfect and I got my results. :)
    – jHz
    Commented Sep 9, 2016 at 9:23
1

I suggest you use SCP instead. Here are a few examples:

scp picture1.jpeg [email protected]:/home/remoteuser/place

Specifying a port with SCP

scp -P 1337 picture1.jpeg [email protected]:/home/remoteuser/place

Send files FROM remote host to local:

scp [email protected]:/home/remoteuser/place/picture2.jpg /home/localuser

You could always check

man scp

for mor information

1

I have a sample shell script below . You may tweak this as per your need. Since you mentioned you already have a host file and you have keys to access the pi's without password

I expected that your hosts.txt will be as below

10.17.36.133
10.17.36.134

Script

dt=`date +%d%m%Y`
for ipaddr in `cat hosts.txt`
do
    dirname=echo "$ipaddr-$dt"|sed 's/\./_/g'
    [ -d foo ] || mkdir $dirname
    echo "starting transfer:" $ipaddr
    scp <userid>@$ipaddr:<source path> <destpath>/$dirname
    echo "completed"
done

Let me know if you have questions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.