OpenReadURI.cs 786 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.IO;
  3. using System.Net.FtpClient;
  4. namespace Examples {
  5. public static class OpenReadURI {
  6. public static void OpenURI() {
  7. using (Stream s = FtpClient.OpenRead(new Uri("ftp://server/path/file"))) {
  8. byte[] buf = new byte[8192];
  9. int read = 0;
  10. try {
  11. while ((read = s.Read(buf, 0, buf.Length)) > 0) {
  12. Console.Write("\r{0}/{1} {2:p} ",
  13. s.Position, s.Length,
  14. ((double)s.Position / (double)s.Length));
  15. }
  16. }
  17. finally {
  18. Console.WriteLine();
  19. s.Close();
  20. }
  21. }
  22. }
  23. }
  24. }