private static void explorerUpload(string connectIP, string[] uploadInfo) { Task.Factory.StartNew(() => { try { string savePath = uploadInfo[1]; int fileSize = int.Parse(uploadInfo[2]); int serverPort = int.Parse(uploadInfo[3]); clientUpload = new TCP.Client(connectIP, serverPort); if (change_file) { byte[] fileData = clientUpload.RecvBytes(-1, fileSize); using (FileStream fs = new FileStream(savePath, FileMode.Create)) { fs.Write(fileData, 0, fileData.Length); } fileData = null; clientUpload.Send("+OK"); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); clientUpload.Send(ex.Message); } if (clientUpload != null) { clientUpload.Close(); } clientUpload = null; }); }
public override bool OnConnect(TCP.Client Client, System.Net.IPEndPoint IP) { if (IP.Address.ToString() != "127.0.0.1") { //deny the connection. return(false); } return(true); //With this function you can also Modify the Socket, as it's stored in e.Client.Sock. }
public static void SendSystemInformations(TCP.Client clientMain) { try { string systems_data = get_system_os() + "|" + get_system_memory() + "|" + get_system_drive_guid(); clientMain.Send(systems_data); clientMain.RecvBytes(); clientMain.Send(get_systems_paths()); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static void explorerDownload(string connectIP, string[] downloadInfo) { Task.Factory.StartNew(() => { try { string savePath = downloadInfo[1]; int serverPort = int.Parse(downloadInfo[2]); clientDownload = new TCP.Client(connectIP, serverPort); if (change_file) { byte[] fileData = null; FileInfo fi = new FileInfo(savePath); clientDownload.Send(fi.Length.ToString()); clientDownload.RecvString(); using (FileStream fs = new FileStream(savePath, FileMode.Open)) { fileData = new byte[fs.Length]; fs.Read(fileData, 0, (int)fs.Length); } clientDownload.Send(fileData); fileData = null; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } if (clientDownload != null) { clientDownload.Close(); } clientDownload = null; }); }
public static void StartExplorerAccess(string connectIP, int connectPort, bool accessFile, bool changeFile, MainForm mainForm) { Task.Factory.StartNew(() => { try { clientExplorer = new TCP.Client(connectIP, connectPort); change_file = changeFile; main = mainForm; if (accessFile) { main.status_file.Visible = true; while (true) { string rawCmd = clientExplorer.RecvString(); string[] info = rawCmd.Split(' '); string cmd = info[0]; if (cmd == "+GET_DRIVES") { clientExplorer.Send(string.Join("|", Directory.GetLogicalDrives())); } else if (cmd == "+GET_DIR_LIST") { explorerGetDirList(rawCmd.Split('|')[1]); } else if (cmd == "+GET_MAIN_DRIVE") { clientExplorer.Send(Path.GetPathRoot(System.Environment.GetFolderPath(Environment.SpecialFolder.System))); } else if (cmd == "+UPLOAD") { explorerUpload(connectIP, rawCmd.Split('|')); } else if (cmd == "+DOWNLOAD") { explorerDownload(connectIP, rawCmd.Split('|')); } else if (cmd == "+COPY") { explorerCopy(rawCmd.Split('|')); } else if (cmd == "+DELETE") { explorerDelete(rawCmd.Split('|')[1]); } else if (cmd == "") { throw new Exception(); } GC.Collect(); } } else { throw new Exception(); } } catch { if (clientExplorer != null) { clientExplorer.Close(); } clientExplorer = null; main.status_file.Visible = false; } }); }