Пример #1
0
        private SFTPCon CreateManagedConnection(bool changeDir)
        {
            //If the request is for a connection initialized to the right dir, we can use the cached version
            if (changeDir && m_con != null)
                return m_con;

            try
            {
                SFTPCon con;
                string keyfile;
                m_options.TryGetValue(SSH_KEYFILE_OPTION, out keyfile);

                if ((keyfile ?? "").Trim().Length > 0)
                {
                    ValidateKeyFile(m_options[SSH_KEYFILE_OPTION]);

                    con = new SFTPCon(m_server, m_username);
                    con.AddIdentityFile(m_options[SSH_KEYFILE_OPTION], m_password);
                }
                else
                    con = new SFTPCon(m_server, m_username, m_password);

                con.Connect(m_port);

                try
                {
                    if (!m_noCdCommand && !string.IsNullOrEmpty(m_path) && changeDir)
                        con.SetCurrenDir(m_path);
                }
                catch (Exception ex)
                {
                    throw new Interface.FolderMissingException(string.Format(Strings.SSHBackend.FolderNotFoundManagedError, m_path, ex.Message), ex);
                }

                //If the connection is initialized to the right folder, we cache it
                if (changeDir)
                    m_con = con;

                return con;
            }
            catch (Tamir.SharpSsh.jsch.SftpException sx)
            {
                throw ReshapeSharpSSHException(sx);
            }
        }
Пример #2
0
 public void Dispose()
 {
     if (m_con != null)
     {
         m_con.Dispose();
         m_con = null;
     }
 }