Exemplo n.º 1
0
 public void Download(string source, Stream destination)
 {
     using (var sourceStream = File.OpenRead(source))
     {
         FileSystemExtensions.Copy(sourceStream, destination);
     }
 }
        public void Copy_Not_Readable()
        {
            Stream source = Stream.Null;
            Stream dest   = File.Create("Copy_dest.txt");

            dest.Close();
            FileSystemExtensions.Copy(source, dest);
        }
        //Здесь должны быть тесты для Copy с нормальными потоками
        public void Copy()
        {
            Stream dest   = File.Create("Copy_dest.txt");
            Stream source = File.Create("Copy_source.txt");

            FileSystemExtensions.Copy(source, dest);
            source.Close();
            dest.Close();
        }
Exemplo n.º 4
0
        public bool Upload(Stream source, string destination)
        {
            using (var destinationStream = File.Open(destination, FileMode.Create))
            {
                FileSystemExtensions.Copy(source, destinationStream);
            }

            return(true);
        }
Exemplo n.º 5
0
        public void Download(string source, Stream destination)
        {
            var request2 = (FtpWebRequest)WebRequest.Create(source);

            request2.Method      = WebRequestMethods.Ftp.DownloadFile;
            request2.Credentials = Credentials;

            using (var response = (FtpWebResponse)request2.GetResponse())
            {
                var stream = response.GetResponseStream();
                FileSystemExtensions.Copy(stream, destination);
            }
        }
Exemplo n.º 6
0
        public bool Upload(Stream source, string destination)
        {
            // Get the object used to communicate with the server.
            var request = (FtpWebRequest)WebRequest.Create(destination);

            request.Method = WebRequestMethods.Ftp.UploadFile;

            request.Credentials = Credentials;

            // Copy the contents of the file to the request stream.
            request.ContentLength = source.Length;
            using (var requestStream = request.GetRequestStream())
            {
                FileSystemExtensions.Copy(source, requestStream);
            }

            using (var response = (FtpWebResponse)request.GetResponse())
            {
                return(FtpStatusCode.ClosingData == response.StatusCode);
            }
        }