3Dshock/server/download.py

46 lines
1.1 KiB
Python

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 + '.tmp')
print('Grabbing file', source_file)
sftp.get(source_file, dest_file)
sftp.remove(source_file)
done_file = dest / f
dest_file.rename(done_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/'))