Fixed uploads, again
This commit is contained in:
3
main.py
3
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():
|
||||
|
||||
@@ -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.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user