private static async Task <SshCommandResult> SysLog(ISshSession session, string logTag, string message) { string Escape(string text) => text == null ? null : $"\"{text.Replace("\"", "\\\"")}\""; var tag = $"{logTag}[ssh user:{session.CurrentUser}]"; return(await session.Run($"logger -t {Escape(tag)} {Escape(message)}").ConfigureAwait(false)); }
public SftpFsOperation(ISshSession session, ISftpAccount account) { this.session = session; this.stat_cache = new SftpStatCache(this); //this.cache=new RemoteEasyCache(this,session.Message); this.cache = new RemoteDiskCache(this, session.Message); this.closer = new FileAutoCloser(cache); this.account = account; // resolve_path string path_remote = account.ServerRoot; if (path_remote == null) { path_remote = ""; } if (path_remote[path_remote.Length - 1] == '/') { path_remote = path_remote.Substring(0, path_remote.Length - 1); } this.path_remote = path_remote; }
protected override void configure(OpenSshConfig.Host hc, ISshSession session) { // No additional configuration required. }
/// <summary> /// Close (or recycle) a session to a host. /// </summary> /// <param name="session"> /// a session previously obtained from this factory's /// <see cref="getSession"/> method. /// </param> public void releaseSession(ISshSession session) { if (session == null) throw new System.ArgumentNullException("session"); if (session.IsConnected) session.Disconnect(); }
/// <summary> /// Provide additional configuration for the session based on the host /// information. This method could be used to supply {@link UserInfo}. /// </summary> /// <param name="hc">host configuration</param> /// <param name="session">session to configure</param> protected abstract void configure(OpenSshConfig.Host hc, ISshSession session);
public override void close() { if (_sock == null) return; try { _sch.releaseSession(_sock); } finally { _sock = null; } #if DEBUG GC.SuppressFinalize(this); // Disarm lock-release checker #endif }
/// <summary> /// Initialize SSH session /// </summary> protected void InitSession() { if (_sock != null) return; int tms = Timeout > 0 ? Timeout * 1000 : 0; string user = Uri.User; string pass = Uri.Pass; string host = Uri.Host; int port = Uri.Port; try { _sock = _sch.getSession(user, pass, host, port); if (!_sock.IsConnected) { _sock.Connect(tms); } } catch (SocketException e) { throw new TransportException(e.Message, e.InnerException ?? e); } catch (Exception je) { throw new TransportException(Uri, je.Message, je.InnerException); } }