Posts

Showing posts from January, 2022

Transfer Files To SFTP Using WinSCP in C#

Image
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();

PGP Encryption and Decryption in C#

Image
Add package called PgpCore from NuGet Package manager. Code example: using (PGP pgp = new PGP()) { // Generate keys pgp.GenerateKey(@"C:\TEMP\keys\public.asc", @"C:\TEMP\keys\private.asc", "email@email.com", "password"); // Encrypt file pgp.EncryptFile(@"C:\TEMP\keys\content.txt", @"C:\TEMP\keys\content__encrypted.pgp", @"C:\TEMP\keys\public.asc", true, true); // Encrypt and sign file pgp.EncryptFileAndSign(@"C:\TEMP\keys\content.txt", @"C:\TEMP\keys\content__encrypted_signed.pgp", @"C:\TEMP\keys\public.asc", @"C:\TEMP\keys\private.asc", "password", true, true); // Decrypt file pgp.DecryptFile(@"C:\TEMP\keys\content__encrypted.pgp", @"C:\TEMP\keys\content__decrypted.txt", @"C:\TEMP\keys\private.asc", "password"); // Decrypt signed file pgp.DecryptFile(@"C:\TEMP\keys\content_...

How to call Web Service (GET/POST) from MS Dynamics NAV C/AL

Image
//Get url := 'https://httpbin.org/ip'; CREATE(WinHttp); WinHttp.Open('GET',url,FALSE); WinHttp.Send(JsonTxt); JsonTxt := WinHttp.ResponseText; MESSAGE(FORMAT(JsonTxt)); //Post url := 'https://reqbin.com/echo/post/json'; CREATE(WinHttp); WinHttp.Open('POST',url,FALSE); WinHttp.SetRequestHeader('Content-Type', 'application/json'); CREATE(XMLDoc); NodeText := XMLDoc.createTextNode(''); NodeText.appendData('{ "Id": 78912'); NodeText.appendData( '"Customer": "Jason Sweet",'); NodeText.appendData('"Quantity": 1,'); NodeText.appendData( '"Price": 18.00}'); WinHttp.Send(NodeText.nodeValue); JsonTxt := WinHttp.ResponseText; MESSAGE(FORMAT(JsonTxt)); Variables: Name DataType Subtype Length ResponseStream InStream     ResponseBuffer BigText   ...