protected override void ProcessRecord() { this.Session ??= new SshSession() { Server = this.Server, Port = this.Port, User = this.User, Password = this.Password, KeyboardInteractive = this.KeyboardInteractive, Effemeral = true, }; // 宛先に変数が含まれている場合、事前にSSHでコマンドを実行してパスを取得 if (candidate_envChar.Any(x => RemotePath.Contains(x))) { this.RemotePath = Session.ExecCommandOneLine($"echo {RemotePath}"); } // ダウンロード先パスの末尾に「\\」「/」が含まれている場合、対象ディレクトリ配下パスに変更 if (candidate_dirSeparator.Any(x => LocalPath.EndsWith(x))) { this.LocalPath = GetPathFromDirectory(RemotePath, LocalPath); } var client = Session.CreateAndConnectSftpClient(); if (client.IsConnected) { using (var fs = File.OpenWrite(LocalPath)) { client.DownloadFile(RemotePath, fs); } } Session.CloseIfEffemeral(); }
protected override void ProcessRecord() { this.Session ??= new SshSession() { Server = this.Server, Port = this.Port, User = this.User, Password = this.Password, KeyboardInteractive = this.KeyboardInteractive, Effemeral = true, }; // 宛先に変数が含まれている場合、事前にSSHでコマンドを実行してパスを取得 if (candidate_envChar.Any(x => RemotePath.Contains(x))) { this.RemotePath = Session.ExecCommandOneLine($"echo {RemotePath}"); } // アップロード先パスの末尾に「\\」「/」が含まれている場合、対象ディレクトリ配下パスに変更 if (candidate_dirSeparator.Any(x => LocalPath.EndsWith(x))) { this.RemotePath = GetPathFromDirectory( LocalPath, RemotePath, Session.CheckRemotePlatform()); } var client = Session.CreateAndConnectScpClient(); if (client.IsConnected) { client.RemotePathTransformation = RemotePathTransformation.ShellQuote; client.Upload(new FileInfo(LocalPath), RemotePath); } Session.CloseIfEffemeral(); }