Ejemplo n.º 1
0
        private FtpDataStream GetStream(long offset, TransferDirection dir)
        {
            m_parent.CheckSessionCurrentDirectory();
            SessionConnected session = m_parent.FtpSession;

            if (offset != 0)
            {
                session.ControlChannel.REST(offset);
            }
            FtpDataStream stream = session.ControlChannel.GetPassiveDataStream(dir);

            try
            {
                if (dir == TransferDirection.Download)
                {
                    session.ControlChannel.RETR(m_name);
                }
                else
                {
                    session.ControlChannel.STOR(m_name);
                }
            }
            catch (Exception)
            {
                stream.Dispose();
                throw;
            }
            return(stream);
        }
Ejemplo n.º 2
0
        public FtpFile CreateFile(string newFileName)
        {
            FtpDataStream stream = CreateFileStream(newFileName);

            stream.Close();
            return((FtpFile)m_files[newFileName]);
        }
Ejemplo n.º 3
0
 internal void EndDataTransfer()
 {
     lock (this)
     {
         if (m_dataStream == null)
         {
             throw new InvalidOperationException();
         }
         m_dataStream = null;
     }
 }
Ejemplo n.º 4
0
 internal void BeginDataTransfer(FtpDataStream stream)
 {
     lock (this)
     {
         if (m_dataStream != null)
         {
             throw new FtpDataTransferException();
         }
         m_dataStream = stream;
     }
 }
Ejemplo n.º 5
0
        // You can only aborting file transfer started by
        // BeginPutFile and BeginGetFile
        override public void AbortTransfer()
        {
            // Save a copy of m_dataStream since it will be set
            // to null when FtpDataStream call EndDataTransfer
            FtpDataStream tempDataStream = m_dataStream;

            if (tempDataStream != null)
            {
                tempDataStream.Abort();
                while (!tempDataStream.IsClosed)
                {
                    System.Threading.Thread.Sleep(0);
                }
            }
        }
Ejemplo n.º 6
0
        public FtpOutputDataStream CreateFileStream(string newFileName)
        {
            InitHashtable();
            FtpDataStream stream = m_session.ControlChannel.GetPassiveDataStream(TransferDirection.Upload);

            try
            {
                m_session.ControlChannel.STOR(newFileName);
                FtpFile newFile = new FtpFile(this, newFileName);
                m_files[newFileName] = newFile;
                return((FtpOutputDataStream)stream);
            }
            catch (Exception)
            {
                stream.Dispose();
                throw;
            }
        }
Ejemplo n.º 7
0
        internal Queue List(bool passive)
        {
            const string errorMsgListing = "Error when listing server directory.";

            try
            {
                Type(TransferMode.Ascii);
                FtpDataStream dataStream = GetPassiveDataStream();

                Queue lineQueue = new Queue();
                FtpCommand("LIST");
                if (m_lastResponse.Code != FtpResponse.DataChannelOpenedTransferStart &&
                    m_lastResponse.Code != FtpResponse.FileOkBeginOpenDataChannel)
                {
                    throw new FtpException(errorMsgListing, m_lastResponse);
                }

                StreamReader lineReader = new StreamReader(dataStream, System.Text.Encoding.Default);

                string line;
                while ((line = lineReader.ReadLine()) != null)
                {
                    lineQueue.Enqueue(line);
                }

                lineReader.Close();
                if (m_lastResponse.Code != FtpResponse.ClosingDataChannel)
                {
                    throw new FtpException(errorMsgListing, m_lastResponse);
                }

                return(lineQueue);
            }
            catch (IOException ie)
            {
                throw new FtpException(errorMsgListing, ie);
            }
            catch (SocketException se)
            {
                throw new FtpException(errorMsgListing, se);
            }
        }
Ejemplo n.º 8
0
        internal void StartTransfer()
        {
            FileStream    localStream  = null;
            FtpDataStream remoteStream = null;

            try
            {
                m_beginEvent(this);
                localStream  = new FileStream(m_localFile, m_localFileOpenMode);
                remoteStream = m_session.ControlChannel.GetPassiveDataStream(m_transferDirection);

                m_ftpFileCommandRoutine(m_remoteFile);
                m_streamCopyRoutine(remoteStream, localStream);

                remoteStream.Close();
                TestTransferResult();

                m_endEvent(this);
            }
            catch (FtpUserAbortException)
            {
                remoteStream.Close();
                throw;
            }
            catch (Exception)
            {
                m_endEvent(this);
                throw;
            }
            finally
            {
                if (remoteStream != null)
                {
                    remoteStream.Dispose();
                }
                if (localStream != null)
                {
                    localStream.Close();
                }
            }
        }