You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
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.exists(): |
|
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() |
|
|
|
if __name__ == '__main__': |
|
from pathlib import Path |
|
download_all_photos(Path('test/'))
|
|
|