ConnectSFTPCmdlet.cs
using Renci.SshNet;
using System; using System.Collections.Generic; using System.Management.Automation; using System.Text; namespace SFTPSyncer { [Cmdlet(VerbsCommunications.Connect, "SFTP")] [OutputType(typeof(SftpClient))] public class ConnectSFTPCmdlet : Cmdlet { [Parameter(Position = 0, Mandatory = true)] [ValidateNotNullOrEmpty()] public string Server { get; set; } [Parameter(Mandatory = false)] public int Port { get; set; } = 22; [Parameter(Mandatory = false)] public string Username { get; set; } [Parameter(Mandatory = false)] public string Password { get; set; } protected override void ProcessRecord() { base.ProcessRecord(); var coni = new ConnectionInfo(Server, port: Port, username: Username, authenticationMethods: new PasswordAuthenticationMethod(Username, Password)); var cl = new SftpClient(coni); WriteObject(cl); // This is what actually "returns" output. } } } |