コード例 #1
0
        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);
        }