In this post, we’ll check out file transfer in Python 3 with file size verification check.
In many Python scripts you’ll come across the need for sending and receiving files over the network, so I decided to make this tutorial for a simple yet stable set of scripts to implement whenever needed.
We’ll only use standard Python libraries included with a default installation: socket, time, os and sys.
One nice little detail we’ll implement is file size verification, so that the receiving party can be sure they received the file with the exact amount of bytes the sender intended.
We’re off to part five of our little Python control server.
I had been postponing this, but its time we implement multiple clients!
I knew we had to do this right and that it would most likely bloat the scripts as well, so it would also require breaking it down into specific modules.
So yeah, that’s what we’re doing, lets get into it!
But before that, let me give you guys some context into the code…
Modular Programming
Many times when working on a project, as it begins to expand and get into a few hundred lines of code we need to start breaking it up into modules.
For our project, so far, it seems most of the functionality is divided between server configuration and data encryption.
I figure, just for the sake of development and teaching proper methods to keep working in a program without feeling like its a labyrinth, we’ll go ahead and separate our code into a few modules.
In this part we’ll be implementing file transfer and encryption.
I use these programs on my own system and you absolutely have to be able to download and upload files in order to get anything done.
Now some of you might remember in part three I mentioned that our encrypted channel wasn’t stable enough to handle several megabytes of data without any mishaps.
Because of that, I had to implement file encryption and decryption in the client as well, since we’re already working with pyAesCrypt anyway.
This allows us to, at the very least, encrypt files locally before sending them over a standard tcp tunnel – or keep them encrypted on the system.
Like much of the functionality we’re going through here, these functions could be copied and used in other code without much hassle.
We’re off to another series: Python Control Server.
Yes, there’s three series going on at once in the blog, so what! 😀
I like having multiple things going so that I don’t have to think much whenever I have some free time to code. I can just sit down and choose whichever series/project to work on at the moment.
Anyway, many people emailed me to post my old videos (from like 10 years ago) from this same series – written in Python 2.X.
It’s also worth mentioning that some of the libraries I used back then have not been properly ported over to Python 3. Overall it just makes a lot of sense to redo the project using more current libraries.
Control Server
Why make a Python Control Server?
For many (ahem, very educational) reasons of course! Like for example, we are two days away from Christmas and many people enjoy taking vacations around this time. Well, why not setup a nice control server to have access to your systems while your away?
Sounds like a good idea time to me!
About Christmas though, I had my first batch of family visiting and let me tell you… its rather easy to get a cold when there’s a lot of people in the same household for hours at a time. So pardon my voice in the video.
We’ve put a lot of work in these past five parts and today is no exception, however, we’ll try to take it easy after that insanity in the last article.
Looking back I probably should’ve broken that last article in more parts. At the same time, I guess it serves to separate the kittens from the lions. 😀
Enough jokes for now, let’s keep moving…
Today we’ll be implementing the second part to the text-based user interface which is what I call the active client chat screen.
Of course this also requires us to first implement the logging system for all of our clients, along with notifications as well.
Besides that we’ll add a few more features to wrap it up.
Dive Into The Code
I’m gonna focus on the main blocks of code added this time, so right off the bat, let’s jump into the new ‘active client chat screen’ interface…
Recent Comments