Exemple #1
0
 public void RenameFileLegacy(SFTPRenameArgument renameArgument, CallbackContext callbackContext)
 {
     try
     {
         var sftpResult = RenameFile(renameArgument);
         _sftpClient.Close();
         _sftpClient = null;
         callbackContext.SendPluginResult(new PluginResult(PluginResult.Status.OK, sftpResult));
     }
     catch (Exception ex)
     {
         m_Logger.Error(ex);
         callbackContext.Error(new
         {
             type    = "Exception",
             code    = "",
             message = ex.Message,
             details = ex.StackTrace
         });
     }
 }
Exemple #2
0
        public CommandResult InternalExecute(ICommandTarget target, params IAdaptable[] args)
        {
            ISSHConnection sshConnection = GetSSHConnection(target) as ISSHConnection;

            if (sshConnection == null || sshConnection.SSHProtocol != SSHProtocol.SSH2)
            {
                return(CommandResult.Ignored);
            }

            string connectionName = GetTerminalName(target);

            if (connectionName == null)
            {
                connectionName = SFTPPlugin.Instance.StringResource.GetString("Common.UnknownPeer");
            }

            Form ownerForm = GetForm(target);

            if (!ConfirmToUse(ownerForm, "SFTP"))
            {
                return(CommandResult.Cancelled);
            }

            SFTPClient sftp = null;

            try {
                sftp = SFTPClient.OpenSFTPChannel(sshConnection);

                SFTPForm form = new SFTPForm(ownerForm, sftp, connectionName);
                form.Show();    // Note: don't specify owner to avoid fixed z-order.

                return(CommandResult.Succeeded);
            }
            catch (Exception e) {
                if (sftp != null)
                {
                    try {
                        sftp.Close();
                    }
                    catch (Exception) {
                    }
                    sftp = null;
                }

                RuntimeUtil.ReportException(e);
                return(CommandResult.Failed);
            }
        }
Exemple #3
0
        private void SFTPForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing && !_closedByOwner)
            {
                if (_sftpThread != null && _sftpThread.IsAlive)
                {
                    e.Cancel = true;
                    return;
                }
            }

            _formClosed = true;

            if (_sftpThread != null && _sftpThread.IsAlive)
            {
                _sftpThread.Abort(); // FIXME: we need graceful cancellation
            }
            try {
                _sftp.Close();
            }
            catch (Exception ex) {
                RuntimeUtil.ReportException(ex);
            }
        }