Exemplo n.º 1
0
        public void FxpCopyAsync(string fileName, FtpClient destination)
        {
            if (base.AsyncWorker != null && base.AsyncWorker.IsBusy)
            {
                throw new InvalidOperationException("The FtpConnection object is already busy executing another asynchronous operation.  You can only execute one asynchronous method at a time.");
            }

            base.CreateAsyncWorker();
            base.AsyncWorker.WorkerSupportsCancellation = true;
            base.AsyncWorker.DoWork += new DoWorkEventHandler(FxpCopyAsync_DoWork);
            base.AsyncWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(FxpCopyAsync_RunWorkerCompleted);
            Object[] args = new Object[2];
            args[0] = fileName;
            args[1] = destination;
            base.AsyncWorker.RunWorkerAsync(args);
        }
Exemplo n.º 2
0
        private void CreateConnection(bool secure)
        {
            if (secure)
            {
                _ftpClient = new FtpClient(Communications.Settings.Url, 990, Ftp.FtpSecurityProtocol.Ssl3Implicit);
                _ftpClient.ValidateServerCertificate += new EventHandler<Communications.Net.Ftp.ValidateServerCertificateEventArgs>(ValidateServerCertificate);
            }
            else
            {
                _ftpClient = new FtpClient(Communications.Settings.Url, 21);
            }

            _ftpClient.FileTransferType = Communications.Net.Ftp.TransferType.Binary;
            _ftpClient.DataTransferMode = Communications.Net.Ftp.TransferMode.Passive;
            _ftpClient.Open(Communications.Settings.UserName, Communications.Settings.Password);
        }
Exemplo n.º 3
0
        public void FxpCopy(string fileName, FtpClient destination)
        {
            if (this.IsConnected == false)
            {
                throw new FtpException("The connection must be open before a transfer between servers can be initiated.");
            }

            if (destination == null)
            {
                throw new ArgumentNullException("destination");
            }

            if (destination.IsConnected == false)
            {
                throw new FtpException("The destination object must be open and connected before a transfer between servers can be initiated.");
            }

            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            if (fileName.Length == 0)
            {
                throw new ArgumentException("must have a value", "fileName");
            }

            try
            {
                destination.SendRequest(new FtpRequest(base.CharacterEncoding, FtpCmd.Pasv));
            }
            catch (FtpException fex)
            {
                throw new FtpException(String.Format("An error occurred when trying to set up the passive connection on '{1}' for a destination to destination copy between '{0}' and '{1}'.", this.Host, destination.Host), base.LastResponse, fex);
            }

            int startIdx = destination.LastResponse.Text.IndexOf("(") + 1;
            int endIdx = destination.LastResponse.Text.IndexOf(")");
            string dataPortInfo = destination.LastResponse.Text.Substring(startIdx, endIdx - startIdx);

            try
            {
                this.SendRequest(new FtpRequest(base.CharacterEncoding, FtpCmd.Port, dataPortInfo));
            }
            catch (FtpException fex)
            {
                throw new FtpException(String.Format("Command instructing '{0}' to open connection failed.", this.Host), base.LastResponse, fex);
            }

            try
            {
                this.SendRequest(new FtpRequest(base.CharacterEncoding, FtpCmd.Retr, fileName));
            }
            catch (FtpException fex)
            {
                throw new FtpException(String.Format("An error occurred transferring on a server to server copy between '{0}' and '{1}'.", this.Host, destination.Host), base.LastResponse, fex);
            }

            try
            {
                destination.SendRequest(new FtpRequest(base.CharacterEncoding, FtpCmd.Stor, fileName));
            }
            catch (FtpException fex)
            {
                throw new FtpException(String.Format("An error occurred transferring on a server to server copy between '{0}' and '{1}'.", this.Host, destination.Host), base.LastResponse, fex);
            }

            destination.WaitForHappyCodes(this.FxpTransferTimeout, FtpResponseCode.RequestedFileActionOkayAndCompleted, FtpResponseCode.ClosingDataConnection);
            this.WaitForHappyCodes(this.FxpTransferTimeout, FtpResponseCode.RequestedFileActionOkayAndCompleted, FtpResponseCode.ClosingDataConnection);
        }
Exemplo n.º 4
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
         if (_ftpClient != null)
         {
             _ftpClient.Dispose();
             _ftpClient = null;
         }
 }