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

Popular posts from this blog

Understanding the Difference Between Assembly Order and Production Order in Dynamics 365 Business Central

Microsoft Dynamics NAV - Creating and Consuming a Codeunit Web Service

Different use of AL Find Functions for Filters in Dynamics 365 Business Central