示例#1
0
        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);
            }
        }