Exemplo n.º 1
0
        /// <summary>
        ///     Connect with remote host
        /// </summary>
        /// <param name="obj"></param>
        private void Connect(PasswordBox obj)
        {
            if (!IsConnected)
            {
                try
                {
                    if (ProtocolMode.Equals("SFTP"))
                    {
                        _protocol = new Sftp();
                    }
                    if (ProtocolMode.Equals("FTP"))
                    {
                        _protocol = new Ftp();
                    }
                    if (ProtocolMode.Equals("FTPS"))
                    {
                        _protocol = new Ftps();
                    }

                    IsConnected = _protocol.Connect(Server, Port, User, obj.Password);
                    RemotePath  = _protocol.WorkingDirectory();

                    if (IsConnected)
                    {
                        RemoteItems = new ObservableCollection <ProtocolItem>(_protocol.ListDirectory(RemotePath));
                    }
                }
                catch (Exception)
                {
                    // We need some data
                }
            }
            else
            {
                IsConnected = !_protocol.Disconnect();
                _protocol   = null;
                RemotePath  = null;
                RemoteItems.Clear();
                Tasks.Clear();
            }
        }