parent
23f15aed34
commit
d1f527c93b
3 changed files with 138 additions and 0 deletions
@ -0,0 +1,42 @@ |
||||
import os |
||||
import settings |
||||
import threading |
||||
import paramiko |
||||
import time |
||||
paramiko.util.log_to_file('paramiko.log') |
||||
|
||||
def download(ip, dest): |
||||
print('Downloading from', ip) |
||||
|
||||
port = 22 |
||||
transport = paramiko.Transport((ip, port)) |
||||
transport.connect(None, settings.RASPBERRY_USER, settings.RASPBERRY_PASS) |
||||
|
||||
sftp = paramiko.SFTPClient.from_transport(transport) |
||||
|
||||
files = sftp.listdir('/3dscan/') |
||||
|
||||
for f in files: |
||||
source_file = '/3dscan/' + f |
||||
dest_file = dest + f |
||||
print('Grabbing file', source_file) |
||||
sftp.get(source_file, dest_file) |
||||
sftp.remove(source_file) |
||||
|
||||
if sftp: sftp.close() |
||||
if transport: transport.close() |
||||
|
||||
print('Finished downloading from', ip) |
||||
|
||||
def download_all_photos(dest): |
||||
if not dest.endswith('/'): |
||||
raise Exception('Destination must end with /') |
||||
|
||||
if not os.path.exists(dest): |
||||
raise Exception('Destination does not exist') |
||||
|
||||
print('Downloading all photos to', dest) |
||||
|
||||
for ip in settings.RASPBERRY_IPS: |
||||
t = threading.Thread(target=download, args=(ip, dest)) |
||||
t.start() |
Loading…
Reference in new issue