123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using System;
- using System.Reflection;
- using System.Text.RegularExpressions;
- using System.Diagnostics;
- namespace System.Net.FtpClient {
-
-
-
- public class FtpDataStream : FtpSocketStream {
- FtpReply m_commandStatus;
-
-
-
-
- public FtpReply CommandStatus {
- get {
- return m_commandStatus;
- }
- set {
- m_commandStatus = value;
- }
- }
- FtpClient m_control = null;
-
-
-
-
-
-
- public FtpClient ControlConnection {
- get {
- return m_control;
- }
- set {
- m_control = value;
- }
- }
- long m_length = 0;
-
-
-
-
- public override long Length {
- get {
- return m_length;
- }
- }
- long m_position = 0;
-
-
-
- public override long Position {
- get {
- return m_position;
- }
- set {
- throw new InvalidOperationException("You cannot modify the position of a FtpDataStream. This property is updated as data is read or written to the stream.");
- }
- }
-
-
-
-
-
-
-
- public override int Read(byte[] buffer, int offset, int count) {
- int read = base.Read(buffer, offset, count);
- m_position += read;
- return read;
- }
-
-
-
-
-
-
- public override void Write(byte[] buffer, int offset, int count) {
- base.Write(buffer, offset, count);
- m_position += count;
- }
-
-
-
-
- public override void SetLength(long value) {
- m_length = value;
- }
-
-
-
-
-
- public void SetPosition(long pos) {
- m_position = pos;
- }
-
-
-
-
- protected override void Dispose(bool disposing) {
- if (disposing) {
- if (IsConnected)
- Close();
- m_control = null;
- }
- base.Dispose(disposing);
- }
-
-
-
- public new FtpReply Close() {
- base.Close();
- try {
- if (ControlConnection != null)
- return ControlConnection.CloseDataStream(this);
- }
- finally {
- m_commandStatus = new FtpReply();
- m_control = null;
- }
- return new FtpReply();
- }
-
-
-
-
- public FtpDataStream(FtpClient conn) {
- if (conn == null)
- throw new ArgumentException("The control connection cannot be null.");
- ControlConnection = conn;
-
-
-
- ValidateCertificate += new FtpSocketStreamSslValidation(delegate(FtpSocketStream obj, FtpSslValidationEventArgs e) {
- e.Accept = true;
- });
- m_position = 0;
- }
-
-
-
- ~FtpDataStream() {
- try {
- Dispose();
- }
- catch (Exception ex) {
- FtpTrace.WriteLine("[Finalizer] Caught and discarded an exception while disposing the FtpDataStream: {0}", ex.ToString());
- }
- }
- }
- }
|