 Right, so hey guys and welcome to the part 4 of creating a back to program using Python This tutorial is really where it's going to get interesting because this time we're going to learn how to actually download remote files from the Target computer using our server and slave program So before we start this tutorial what you want to do is create a new folder destination just so that we can test this to File what you want to do is call this Let's say Example slave Destination Let's assume. This is the the slave program is actually running on a target computer for now And this is the directory that it is in and let's just create some sample files here like this word file Let's call it um test and we can just open this file and type in This is Important file. Okay, so we now have a file named as test doc docs And then we've put this and the slave program in the example slave destination Which could be the computer where the slave file is running. So now what we want to do is edit the server and the slave file and Add a code in to download our custom files So first of all, let's get them side-by-side What you want to do is Let's see the command that we're going to use to download the file. So the command we're going to use to download files is going to be Let's just say download Files well Files from the directory right So what you want to do next is go ahead and register this command How we're going to do this is just copy this LF statement right here And then we're just going to paste it below that and this one is going to be called obviously Download file, which we just decided upon a second ago And first of all what we're going to do is obviously we're sending the command over to the slave program So in order for it to be recognized here We need to also copy this and paste it once again So the command is actually Recognized in the slave program or obviously it's not going to work. So you just do download files Right and then File and then we can move on to asking the user for the file. He wants to download So the file he wants to download what we do with that is we can type in file name equals input string Please enter the file link By that I mean the file path. Let's just change that to the file path including file name right So once we have the file path and the file name of the file that we're trying to download from the slave program So bear in mind you're obviously going to have to Do the custom directory first and learn how the C drive in the slave program is worked out and how the directories and stuff are Then you can use that Custom directory link and copy that and paste that here so you can actually find the file You're looking for and then once we have the file name What we're going to do is we're going to send that file name over Let's just rename this to file path because it's really annoying me For okay, so we're going to send that over to our slave program. We do connection dot send file path dot and curd and then we can print Let's not print anything for now So once we go here what we're going to do is we're going to change this to Gonna call this file path Equals as dot receive. Let's just do five thousand for now And then we do file path Equals Dot decode so that we have no unnecessary data in there We only need the ones that we need so first of all what we need to do is we run a call open command So we do open. I mean file Equals open and then what we are opening is going to be obviously the file path underscore path we're opening that and we're opening in the Read read mode There should be something else as well. So we're opening in the read bytes mode. So What we're saying here is we're opening the file which is specified from the server which we've sent over We're opening that and we're opening in the read bytes mode when we're writing the files We will write it as the read bytes for now. We're only reading it. So we're once we've done that. We're gonna overwrite the file Well, actually, we just say data equals File dot read and then once the data has been read. We're gonna send that data over to our What's it called? master program or the server program. So we do s dot send data and code and That does that for now So once the data has been sent over, we're just gonna print here How has been successfully Right, so once we're done with that, we just print a blank one again And again around here so that it's nice and neat and what we want to do Here is go on and Receive the file. So we do File equals connection dot receive Let's just do 10,000 for now So once we're done with that we can do We don't need to decode this. So all we need to do is file new file equals open and For this we're gonna need a file name. So we need to store a file name create a new variable called file name and We're gonna ask the user what he wants to save this file as Please enter a found name for the incoming file including The extension We can obviously automate this but I want to keep this tutorial short so it doesn't get boring for you guys So once we're done with the file name, we're gonna do New file equals open the file name into write bytes mode and then we're gonna do new file Dot right, so oops New file dot right We're gonna get the data. We just received which is file up here Which we just received and then once we're done writing. We're just gonna close the new file Close and we can see print um file name space has been downloaded Downloaded and saved and we can end it right there Let's just do another print right here. Just to keep it neat and tidy I do think I'm missing one step so there might be just one slight error, which we can quickly solve But for now, I'm just gonna run this program to check if it can work Does not match indentation level No Server's running on one side and so is it on the other so we're just gonna get the address for the server Copy and paste that Obviously, if you guys haven't watched the previous tutorials There's already three versions of this video before part one part two part three and this is part four So I really do recommend you guys to go and watch from part one to part three and then carry on with this one Because it will make a lot more sense Obviously, if you guys aren't interested in those ones you can just carry on with this one. So The command we created was download file And then it's asking us for the file path including the file name for now. It's called Test docs. So we need to type in that test doc docs Click enter Objects another attribute to encode. Okay. I just forgot that we didn't have to Encode the data because it is obviously already encoded Before I actually run this again. I just want to make a few changes here because it doesn't look very nice This has nothing to do with the functioning of the program program. Just want it to look a bit more better All right, so we run this again might have another slight error, but we're prepared for that Um, let's copy this I'm gonna paste it right here And then we can do the command which is download file And then the file name is test doc docs File has been sent successfully. Please enter a file name for the incoming file including the extension So we're gonna call this Oops Am I not typing? Yeah, it was So received File doc docs make sure that the extension is same and then once we hit enter Received file doc docs has been downloaded and saved now We're gonna see how true this actually is by closing this down We close this one down as well We just minimize both of these we go to our directory and if we go to One one back As we see right here next to the server file. We've just successfully downloaded our received file doc docs We're gonna open this up to see if all data is in there And there we are it says this is some important file now. We essentially have two copies Because one was residing on the target machine Which we're gonna get the slave program running on and we've used our programming to download that file from the slave program To the server So that's how we did we need to continue the rest of the programming as well But for today that was it. Hope you guys found this interesting. I myself did Um Before we continue I really want to thank you guys for all the subscriptions so far and all the unbelievable support Please make sure to help me reach my target 1000 subscribers by subscribing I'm really grateful to all you guys that have already subscribed And I will be releasing the part five of this tutorial soon where we will be learning how to remove files remotely And maybe we'll move directories at the same time as well With all and next after those we're just gonna keep following this Anyway, that was it for today's tutorial guys I hope you like this. Please make sure to drop a like comment and subscribe And I will see you in the next one. Peace out