UploadSFTPFileCmdlet.cs

using Renci.SshNet;
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Text;
 
namespace SFTPSyncer
{
    [Cmdlet("Upload", "SFTPFile")]
    public class UploadSFTPFileCmdlet : Cmdlet
    {
        [Parameter(Position = 0, Mandatory = true)]
        [ValidateNotNullOrEmpty()]
        public SftpClient Connection { get; set; }
 
 
        [Parameter(Position = 1, Mandatory = true)]
        public string Filename { get; set; }
 
        [Parameter(Position = 2, Mandatory = true)]
        public string Target { get; set; }
 
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            using var inputStr = System.IO.File.OpenRead(Filename);
            Connection.UploadFile(inputStr, Target);
        }
    }
}