public void FileCopyTo(string LocalSourceFileName, string RemoteDestinationFileName) { string cmd = ""; string answer = ""; string resp = ""; string desc = ""; KeyValPair kvp = new KeyValPair(';', ':'); FileInfo fi = new FileInfo(LocalSourceFileName); if (fi.Exists == false) { throw new Exception("Local source file not found!"); } //byte checksum = 0; string destination_dir_path = Globals.GetDirectoryOfFile(RemoteDestinationFileName); cmd = string.Format("req:dir_exists; path:{0};", destination_dir_path); answer = RequestCommand(cmd, 2000); //MessageBox.Show(answer); HandleDeviceEvent(answer); kvp.Clear(); kvp.Fill(answer); resp = kvp.GetVal("resp"); desc = kvp.GetVal("desc"); // add a log here with 'desc' field if (resp == "0") { cmd = string.Format("req:dir_create; path:{0};", destination_dir_path); resp = RequestCommand(cmd, 2000); if (resp == "0") { throw new Exception("Unable to locate destination folder"); } } cmd = string.Format("req:file_create; file_name:{0}; file_length:{1}", RemoteDestinationFileName, fi.Length); answer = RequestCommand(cmd, 2000); //MessageBox.Show(answer); HandleDeviceEvent(answer); kvp.Clear(); kvp.Fill(answer); resp = kvp.GetVal("resp"); desc = kvp.GetVal("desc"); // add a log here with 'desc' field if (resp == "1") // The other side is ready to receive the content of the file. { long total_bytes_sent = SendOutData(LocalSourceFileName); } }
public string FetchFile(string RemoteFullFileName, string LocalDirPath) { string cmd = string.Format("req:file_get_preper_to_send_file; full_file_name:{0};", RemoteFullFileName); string answer = RequestCommand(cmd, 10000); KeyValPair kvp = new KeyValPair(';', ':'); kvp.Fill(answer); string resp = kvp.GetVal("resp"); if (resp == "1") { long file_length = 0; long.TryParse(kvp.GetVal("file_length"), out file_length); cmd = string.Format("req:file_sned_file; full_file_name:{0};", RemoteFullFileName); answer = RequestCommand(cmd, 10000); kvp.Clear(); kvp.Fill(answer); if (kvp.GetVal("resp") == "1") { string remote_root = kvp.GetVal("root"); string remote_full_file_name = kvp.GetVal("full_file_name"); string remote_rel_file_name = remote_full_file_name.Replace(remote_root, ""); string local_full_file_name = LocalDirPath + remote_rel_file_name; local_full_file_name = local_full_file_name.Replace("/", "\\"); this.IncomingFileLength = file_length; this.IncomingFileName = local_full_file_name; string local_path = Globals.GetDirOfFile(local_full_file_name); try { if (Directory.Exists(local_path) == false) { Directory.CreateDirectory(local_path); } this.IncomingStream = new BinaryWriter(new FileStream(IncomingFileName, FileMode.Create)); this.IncomingFileAvailable = true; } catch { // } } } return(answer); }