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); }
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; } }
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(); } } }