示例#1
0
        static void Main(string[] args)
        {
            var info = new SftpInfo()
            {
                Sourcefile  = @"C:\someFIle.csv",
                Destination = @"./",
                Host        = "192.168.10.185",
                UserName    = "******",
                Password    = "******",
                Port        = 22
            };

            Sftp.UploadSFTPFile(info);
        }
示例#2
0
 public static void UploadSFTPFile(SftpInfo info)
 {
     try
     {
         using (SftpClient client = new SftpClient(info.Host, info.Port, info.UserName, info.Password))
         {
             client.Connect();
             client.ChangeDirectory(info.Destination);
             using (FileStream fs = new FileStream(info.Sourcefile, FileMode.Open))
             {
                 client.BufferSize = 4 * 1024;
                 client.UploadFile(fs, Path.GetFileName(info.Sourcefile));
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine("An Error has Occured: " + ex);
     }
 }