Пример #1
0
        public void PutFile(Stream s, string destination)
        {
            var r = HttpWebRequest.Create(uriPrefix + "PutFile?target=" + HttpUtility.UrlEncode(destination));

            r.Proxy         = new WebProxy();
            r.Method        = "POST";
            r.ContentType   = "application/octet-stream";
            r.ContentLength = s.Length;

            using (var reqStream = r.GetRequestStream())
            {
                VMAgent.CopyStream(s, reqStream);
            }

            using (var response = r.GetResponse())
            {
                using (var respStream = response.GetResponseStream())
                {
                    using (var reader = new StreamReader(respStream))
                    {
                        string resp = reader.ReadToEnd();
                        if (resp != "SUCCESS")
                        {
                            throw new Exception("Error! Unable to copy file!");
                        }
                    }
                }
            }
        }
Пример #2
0
        public void GetFile(string source, Stream s)
        {
            var r = HttpWebRequest.Create(uriPrefix + "GetFile?target=" + HttpUtility.UrlEncode(source));

            r.Proxy       = new WebProxy();
            r.Method      = "GET";
            r.ContentType = "application/octet-stream";
            using (var response = r.GetResponse())
            {
                using (var respStream = response.GetResponseStream())
                {
                    VMAgent.CopyStream(respStream, s);
                }
            }
        }