Added custom header to download & better ftp error messages

Changes:
- added custom header to plugin download
- added better sftp/ftp error messages
- removed unnecessary sftp/ftp functions
This commit is contained in:
Neocky
2021-03-31 18:11:41 +02:00
parent 927767b0aa
commit 706b8049c3
6 changed files with 29 additions and 34 deletions

View File

@@ -25,11 +25,6 @@ def ftp_showPlugins(ftp):
print(attr.filename, attr)
def ftp_cdPluginDir(ftp):
configValues = configurationValues()
ftp.cwd(configValues.sftp_folderPath)
def ftp_upload_file(ftp, itemPath):
configValues = configurationValues()
try:
@@ -41,8 +36,8 @@ def ftp_upload_file(ftp, itemPath):
with open (itemPath, 'rb') as plugin_file:
ftp.storbinary('STOR '+ str(itemPath), plugin_file)
except FileNotFoundError:
print(oColors.brightRed + "The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "Aborting uploading." + oColors.standardWhite)
print(oColors.brightRed + "[FTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "[FTP]: Aborting uploading." + oColors.standardWhite)
os.chdir(currentDirectory)
ftp.close()
@@ -58,8 +53,8 @@ def ftp_upload_server_jar(ftp, itemPath):
with open (itemPath, 'rb') as server_jar:
ftp.storbinary('STOR '+ str(itemPath), server_jar)
except FileNotFoundError:
print(oColors.brightRed + "The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "Aborting uploading." + oColors.standardWhite)
print(oColors.brightRed + "[FTP]: The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "[FTP]: Aborting uploading." + oColors.standardWhite)
os.chdir(currentDirectory)
ftp.close()
@@ -70,12 +65,12 @@ def ftp_listAll(ftp):
ftp.cwd(configValues.sftp_folderPath)
installedPlugins = ftp.nlst()
except FileNotFoundError:
print(oColors.brightRed + "The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "[FTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
try:
return installedPlugins
except UnboundLocalError:
print(oColors.brightRed + "No plugins were found." + oColors.standardWhite)
print(oColors.brightRed + "[FTP]: No plugins were found." + oColors.standardWhite)
def ftp_listFilesInServerRoot(ftp):
@@ -83,12 +78,12 @@ def ftp_listFilesInServerRoot(ftp):
ftp.cwd('.')
filesInServerRoot = ftp.nlst()
except FileNotFoundError:
print(oColors.brightRed + "The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "[FTP]: The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
try:
return filesInServerRoot
except UnboundLocalError:
print(oColors.brightRed + "No Serverjar was found." + oColors.standardWhite)
print(oColors.brightRed + "[FTP]: No Serverjar was found." + oColors.standardWhite)
def ftp_downloadFile(ftp, downloadPath, fileToDownload):

View File

@@ -2,7 +2,6 @@ import sys
import os
import pysftp
import paramiko
import ftplib
from utils.consoleoutput import oColors
from handlers.handle_config import configurationValues
@@ -33,18 +32,14 @@ def sftp_showPlugins(sftp):
print(attr.filename, attr)
def sftp_cdPluginDir(sftp):
sftp.cd('plugins')
def sftp_upload_file(sftp, itemPath):
try:
sftp.chdir('plugins')
sftp.put(itemPath)
except FileNotFoundError:
print(oColors.brightRed + "The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "Aborting uploading." + oColors.standardWhite)
print(oColors.brightRed + "[SFTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "[SFTP]: Aborting uploading." + oColors.standardWhite)
sftp.close()
@@ -53,8 +48,8 @@ def sftp_upload_server_jar(sftp, itemPath):
sftp.chdir('.')
sftp.put(itemPath)
except FileNotFoundError:
print(oColors.brightRed + "The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "Aborting uploading." + oColors.standardWhite)
print(oColors.brightRed + "[SFTP]: The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "[SFTP]: Aborting uploading." + oColors.standardWhite)
sftp.close()
@@ -63,24 +58,24 @@ def sftp_listAll(sftp):
sftp.chdir('plugins')
installedPlugins = sftp.listdir()
except FileNotFoundError:
print(oColors.brightRed + "The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "[SFTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
try:
return installedPlugins
except UnboundLocalError:
print(oColors.brightRed + "No plugins were found." + oColors.standardWhite)
print(oColors.brightRed + "[SFTP]: No plugins were found." + oColors.standardWhite)
def sftp_listFilesInServerRoot(sftp):
try:
filesInServerRoot = sftp.listdir()
except FileNotFoundError:
print(oColors.brightRed + "The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
print(oColors.brightRed + "[SFTP]: The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
try:
return filesInServerRoot
except UnboundLocalError:
print(oColors.brightRed + "No Serverjar was found." + oColors.standardWhite)
print(oColors.brightRed + "[SFTP]: No Serverjar was found." + oColors.standardWhite)
def sftp_downloadFile(sftp, downloadPath, fileToDownload):