Files download - upload at live server using python
Hello Friends, Today we're going to cover very useful topic. In this blog, we're gonna learn- how can we "Upload and download files at live server. " so let's get started reading the blog.
This article is useful for the students who are willing to upload or download any files at there live server for their any python applications made with PyQt5 ,Tkinter ,Kivy ,Pyside ,
pySimpleGUI etc.
It's useful for uploading any type of files (like image files,audio files,video files,excel files,database files, text files,video files etc.) at server using python codes.
Here we'll make a system to upload files at server and will also try to download same file from server.
So, i hope you've your hosting credentials (username,password,host IP Address) with you before starting.
and Make sure , You're not showing your credentials to anyone. it's for your data safety.
Watch Video Tutorial for more Clear and live Explanation 👇
file_uploader.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | from ftpretty import ftpretty def upload(filename, user= 'xxxxxx', password='xxxxxxxxxxx', host='xx.xx.xx.xx'): f = ftpretty(host,user,password) only_file_name = filename.split('/')[-1] # c:/f/d/file.txt f.put(filename,'/my_uploads/'+only_file_name) # /home/g/my_uploads/file.txt def download( user= 'xxxxxx', password='xxxxxxxxxxx', host='xx.xx.xx.xx'): f = ftpretty(host,user,password) f.get("/my_uploads/cid-logo-small.png","cid.png") print("File downloaded") if __name__ =="__main__": upload(filename='file_uploader.py') |
How to add this code in you project ❗
install ftpretty module using pip command
then
firstly open "file_uploader.py" file in any python IDE /text editor
Change the host,user and password values in both methods.
and Done!
NOW!
in ur program, u need to import this module/file like this👉
import file_uploader
and then, to upload files -----> call its method "upload()" when required with parameters filename [required] host [optional] user [optional] password [optional] like this👉
file_uploader.upload( filename="your fileName/address")
Done! to download -----> call its method download()" when required with parameters host [optional] user [optional] password [optional] like this👉
file_uploader.download(user=" username[optional] " , password=" password of user[optional] " , host=" server IP Address[optional] ")
Note: Make sure , you've edited the filename in download() method of "file_uploader.py file.
Done!
see tk_example.py to know more about, how to use
import file_uploader
and then, to upload files -----> call its method "upload()" when required with parameters filename [required] host [optional] user [optional] password [optional] like this👉
file_uploader.upload( filename="your fileName/address")
Done! to download -----> call its method download()" when required with parameters host [optional] user [optional] password [optional] like this👉
file_uploader.download(user=" username[optional] " , password=" password of user[optional] " , host=" server IP Address[optional] ")
Note: Make sure , you've edited the filename in download() method of "file_uploader.py file.
Done!
see tk_example.py to know more about, how to use
tk_example.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | from tkinter import * from tkinter import messagebox,filedialog import file_uploader def selectfile(): files = (("text files","*.txt"),("All files","*.*")) file = filedialog.askopenfilename(initialdir='./',title="Upload files", filetypes=files,defaultextension=files) if file: file_uploader.upload(filename=file) messagebox.showinfo("Uploaded",file+" uploaded successfully") root = Tk() root.title("File Uploader Example") root.geometry("420x320") root['bg'] = 'blue3' Label(text="File Uploader Example",bg='black',fg='white', font=15).pack(padx=2,pady=2,fill=X) uButton = Button(root,text="Upload File",relief=GROOVE,width=20,bd=3, command=selectfile) uButton.pack(side=LEFT,padx=150) dButton = Button(root,text="Download File",relief=GROOVE,width=20,bd=3, command=file_uploader.download) dButton.pack(side=RIGHT,padx=150) root.mainloop() |
ScreenShots
Bro, This is not working. Your dialogue box shows not responding.
ReplyDelete