From fe2eb6fbe980d695d96e7bc6ef0cf3604bb879ea Mon Sep 17 00:00:00 2001 From: hyvenet Date: Fri, 22 Aug 2025 20:28:17 +0100 Subject: [PATCH] Fixed uploads, again --- main.py | 3 +-- uploadresults.py | 49 ++++++++++++++++++++++++------------------------ 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/main.py b/main.py index 1392b0b..277ab7c 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,6 @@ import openDrive import time import os from imdb import Cinemagoer -import uploadresults from dotenv import load_dotenv load_dotenv() @@ -24,7 +23,7 @@ def ripDvd(driveName): movieName = driveName os.system('HandBrakeCLI -i /dev/sr0 -o output/"' + movieName + '.mp4" --preset-import-file preset.json') print("- Movie has been ripped, will now procede to upload file") - uploadresults.upload() + os.system("python3 uploadresults.py") print("- Movie has been uploaded") def waitForDvd(): diff --git a/uploadresults.py b/uploadresults.py index 89dca84..2718dc4 100644 --- a/uploadresults.py +++ b/uploadresults.py @@ -2,34 +2,35 @@ import paramiko import os from dotenv import load_dotenv -def upload(): - load_dotenv() - hostname = os.getenv('SFTP_HOST') - port = int(os.getenv('SFTP_PORT')) - username = os.getenv('SFTP_USERNAME') - password = os.getenv('SFTP_PASSWORD') +load_dotenv() - remote_directory = os.getenv('UPLOAD_PATH') - local_directory = 'output/' # Where to save the downloaded files +hostname = os.getenv('SFTP_HOST') +port = int(os.getenv('SFTP_PORT')) +username = os.getenv('SFTP_USERNAME') +password = os.getenv('SFTP_PASSWORD') - # Create an SSH client - ssh_client = paramiko.SSHClient() - ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # Automatically add the server's host key, {Link: according to Medium https://medium.com/nerd-for-tech/paramiko-how-to-transfer-files-with-remote-system-sftp-servers-using-python-52d3e51d2cfa} - ssh_client.connect(hostname, port, username, password) +remote_directory = os.getenv('UPLOAD_PATH') +local_directory = 'output/' # Where to save the downloaded files - # Open an SFTP session - sftp = ssh_client.open_sftp() +# Create an SSH client +ssh_client = paramiko.SSHClient() +ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # Automatically add the server's host key, {Link: according to Medium https://medium.com/nerd-for-tech/paramiko-how-to-transfer-files-with-remote-system-sftp-servers-using-python-52d3e51d2cfa} +ssh_client.connect(hostname, port, username, password) - # List the files in the remote directory - for filename in os.listdir(local_directory): - remote_filepath = os.path.join(remote_directory, filename) - local_filepath = os.path.join(local_directory, filename) +# Open an SFTP session +sftp = ssh_client.open_sftp() - # Download each file - sftp.put(local_filepath, remote_filepath) - print(f"- Uploaded: {local_filepath} to {remote_filepath}") +# List the files in the remote directory +for filename in os.listdir(local_directory): + remote_filepath = os.path.join(remote_directory, filename) + local_filepath = os.path.join(local_directory, filename) - # Close the SFTP session and SSH connection - sftp.close() - ssh_client.close() + # Download each file + sftp.put(local_filepath, remote_filepath) + print(f"Uploaded: {local_filepath} to {remote_filepath}") + +# Close the SFTP session and SSH connection +sftp.close() +ssh_client.close() +print("All files downloaded and connections closed.")