I've made a simple python program to upload files to a server for people in my company to use (it's a short-term solution for now). The user runs the file and it asks them to choose files, which are then uploaded to a server. My code is here:
import os
from tkinter import filedialog, Tk, Label, Button
import paramiko
import urllib.parse
import os
from pathlib import Path
class MyGUI:
def __init__(self, master):
self.master = master
master.title("Server Uploader")
master.resizable(height=False, width=False)
master.configure(bg="white")
self.label = Label(master, text="There was a problem connecting to the server. Please try again later or contact me.", fg="black", bg="white")
self.label.config(font=("Courier", 12))
self.label.pack()
class SuccessfulUpload:
def __init__(self, master):
self.master = master
master.title("Successful Upload")
master.resizable(height=False,width=False)
self.label = Label(master, text="Upload successful. You can now close this window.")
self.label.config(font=("Courier, 12"))
self.label.pack()
#Connect to server using SFTP
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh_client.connect(hostname='hostname',port=portno,username='username',password='password')
except paramiko.ssh_exception.AuthenticationException as e:
root = Tk()
my_gui = MyGUI(root)
root.mainloop()
raise SystemExit
#Ask for user to choose files to upload
root = Tk()
root.withdraw()
files = filedialog.askopenfilenames(title="Choose Files to Upload to the Server", filetypes=(("All Files","*.*"),("PDF Files","*.pdf"), ("Word Files","*.doc*")))
print (root.tk.splitlist(files))
s = ssh_client.open_sftp()
if files == "":
raise SystemExit
#Define local and remote path for file
for file in files:
localpath = file
parts = Path(file).parts
endpath = parts[-1]
print(endpath)
remotepath="/Path/" + endpath
print(remotepath)
s.put(localpath,remotepath)
root = Tk()
fin = SuccessfulUpload(root)
root.mainloop()
s.close()
root.destroy()
complete = input("Upload Successful. Press any key to exit.")
I converted the .py file into a .exe file using pyinstaller. I then sent it to another computer. First, Windows tried to prevent the program from downloading (understandable), then once allowed to download, Windows tries to stop the program from running - bit annoying but OK. Still, after allowing the program twice through Windows, anti-virus (AVG) still prevents the program from running. To get it to run, I've had to go directly onto the anti-virus and make an exception for my program.
I can't send the program out whilst you have to manually make an exception for it within the anti-virus. Is there any way to make your file more trustworthy for other computers to download and run (without anti-virus completely stopping the program from running).