Fixed uploads, again
This commit is contained in:
3
main.py
3
main.py
@@ -2,7 +2,6 @@ import openDrive
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
from imdb import Cinemagoer
|
from imdb import Cinemagoer
|
||||||
import uploadresults
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
@@ -24,7 +23,7 @@ def ripDvd(driveName):
|
|||||||
movieName = driveName
|
movieName = driveName
|
||||||
os.system('HandBrakeCLI -i /dev/sr0 -o output/"' + movieName + '.mp4" --preset-import-file preset.json')
|
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")
|
print("- Movie has been ripped, will now procede to upload file")
|
||||||
uploadresults.upload()
|
os.system("python3 uploadresults.py")
|
||||||
print("- Movie has been uploaded")
|
print("- Movie has been uploaded")
|
||||||
|
|
||||||
def waitForDvd():
|
def waitForDvd():
|
||||||
|
|||||||
@@ -2,34 +2,35 @@ import paramiko
|
|||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
def upload():
|
load_dotenv()
|
||||||
load_dotenv()
|
|
||||||
hostname = os.getenv('SFTP_HOST')
|
|
||||||
port = int(os.getenv('SFTP_PORT'))
|
|
||||||
username = os.getenv('SFTP_USERNAME')
|
|
||||||
password = os.getenv('SFTP_PASSWORD')
|
|
||||||
|
|
||||||
remote_directory = os.getenv('UPLOAD_PATH')
|
hostname = os.getenv('SFTP_HOST')
|
||||||
local_directory = 'output/' # Where to save the downloaded files
|
port = int(os.getenv('SFTP_PORT'))
|
||||||
|
username = os.getenv('SFTP_USERNAME')
|
||||||
|
password = os.getenv('SFTP_PASSWORD')
|
||||||
|
|
||||||
# Create an SSH client
|
remote_directory = os.getenv('UPLOAD_PATH')
|
||||||
ssh_client = paramiko.SSHClient()
|
local_directory = 'output/' # Where to save the downloaded files
|
||||||
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)
|
|
||||||
|
|
||||||
# Open an SFTP session
|
# Create an SSH client
|
||||||
sftp = ssh_client.open_sftp()
|
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
|
# Open an SFTP session
|
||||||
for filename in os.listdir(local_directory):
|
sftp = ssh_client.open_sftp()
|
||||||
remote_filepath = os.path.join(remote_directory, filename)
|
|
||||||
local_filepath = os.path.join(local_directory, filename)
|
|
||||||
|
|
||||||
# Download each file
|
# List the files in the remote directory
|
||||||
sftp.put(local_filepath, remote_filepath)
|
for filename in os.listdir(local_directory):
|
||||||
print(f"- Uploaded: {local_filepath} to {remote_filepath}")
|
remote_filepath = os.path.join(remote_directory, filename)
|
||||||
|
local_filepath = os.path.join(local_directory, filename)
|
||||||
|
|
||||||
# Close the SFTP session and SSH connection
|
# Download each file
|
||||||
sftp.close()
|
sftp.put(local_filepath, remote_filepath)
|
||||||
ssh_client.close()
|
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