Transfer Files To SFTP Using WinSCP in C#
Install WinSCP from NuGet Package manager
Code Example:
//sessionOptions.Protocol = Protocol.Sftp;
sessionOptions.Protocol = Protocol.Ftp;
sessionOptions.HostName = ftpurl;
sessionOptions.UserName = ftpusername;
sessionOptions.Password = ftppassword;
//sessionOptions.SshHostKeyFingerprint = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
Session session = new Session();
session.Open(sessionOptions);
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
//This is for Getting/Downloading files from SFTP
transferResult = session.GetFiles(DirectoryPath, destinationFtpUrl, false, transferOptions);
//This is for Putting/Uploading file on SFTP
transferResult = session.PutFiles(DirectoryPath, destinationFtpUrl, false, transferOptions);
transferResult.Check();
Comments
Post a Comment