Skip to main content

Hi,

Can any advise how to convert below to Visual Cobol?

using System;

using System.IO;

using System.Net;

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;

 

namespace ConnectToFtpDemo

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp:///testFileUpload.txt"); 

                request.Method = WebRequestMethods.Ftp.UploadFile; 

                request.Credentials = new NetworkCredential("Username", "Password");

                request.EnableSsl = true;

                ServicePointManager.ServerCertificateValidationCallback = ServicePointManager_ServerCertificateValidationCallback;

 

                long bytesSent = 0;

                using (Stream requestStream = request.GetRequestStream())

                using (FileStream uploadFileStream = File.OpenRead("C:\\\\Test\\\\test.txt"))

                {

                    uploadFileStream.CopyTo(requestStream);

                    bytesSent = uploadFileStream.Position;

                }

 

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex);

            }

 

            Console.ReadLine();

        }

 

 

        private static bool ServicePointManager_ServerCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

        {

            //TODO: Logic to determine if certificate sent by server on connection is valid if it is return to true otherwise return false

            return true;

 

            //Type type = null;

 

            //var publicKey = certificate.GetPublicKeyString();

            //// Check public key if matche

            //type = certificate.GetType();

            //var p = type.GetProperty("Thumbprint");

            //var thumbPrint = p.GetValue(certificate)?.ToString();

           

 

        }

    }

}

Hi,

Can any advise how to convert below to Visual Cobol?

using System;

using System.IO;

using System.Net;

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;

 

namespace ConnectToFtpDemo

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp:///testFileUpload.txt"); 

                request.Method = WebRequestMethods.Ftp.UploadFile; 

                request.Credentials = new NetworkCredential("Username", "Password");

                request.EnableSsl = true;

                ServicePointManager.ServerCertificateValidationCallback = ServicePointManager_ServerCertificateValidationCallback;

 

                long bytesSent = 0;

                using (Stream requestStream = request.GetRequestStream())

                using (FileStream uploadFileStream = File.OpenRead("C:\\\\Test\\\\test.txt"))

                {

                    uploadFileStream.CopyTo(requestStream);

                    bytesSent = uploadFileStream.Position;

                }

 

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex);

            }

 

            Console.ReadLine();

        }

 

 

        private static bool ServicePointManager_ServerCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

        {

            //TODO: Logic to determine if certificate sent by server on connection is valid if it is return to true otherwise return false

            return true;

 

            //Type type = null;

 

            //var publicKey = certificate.GetPublicKeyString();

            //// Check public key if matche

            //type = certificate.GetType();

            //var p = type.GetProperty("Thumbprint");

            //var thumbPrint = p.GetValue(certificate)?.ToString();

           

 

        }

    }

}

I am not sure if it works or not but something like this should be close:

 

 

      $set ilusing"System""
      $set ilusing"System.IO""
      $set ilusing"System.Net""
      $set ilusing"System.Net.Security""
      $set ilusing"System.Security.Cryptography.X509Certificates""

       class-id ConnectToFtpDemo.Program.
       working-storage section.
       method-id Main static.
       local-storage section.
       procedure division using args as string occurs any.
		   try
             declare request as type FtpWebRequest = type WebRequest::Create("ftp:///testFileUpload.txt") as type FtpWebRequest 
             set request::Method = type WebRequestMethods Ftp::UploadFile
             set request::Credentials = new type NetworkCredential("Username", "Password")
             set request::EnableSsl = true
             set type ServicePointManager::ServerCertificateValidationCallback to method self::ServicePointManager_ServerCertificateValidationCallback
             declare bytesSent as binary-long = 0
             perform using requestStream as type Stream = request::GetRequestStream
				 perform using uploadFileStream as type FileStream = type File::OpenRead("C:\\\\Test\\\\test.txt")
                    invoke uploadFileStream::CopyTo(requestStream)
                    set bytesSent = uploadFileStream::Position
                end-perform
             end-perform
           catch ex as type Exception 
               invoke type Console::WriteLine(ex)
           end-try
		    
           invoke type Console::ReadLine
           goback.
       end method.

       method-id ServicePointManager_ServerCertificateValidationCallback private static.
       local-storage section.
       procedure division using by value sender as object, certificate as type X509Certificate, #chain as type X509Chain, sslPolicyErrors as type SslPolicyErrors
                      returning retbool as condition-value.    
         *>TODO: Logic to determine if certificate sent by server on connection is valid if it is return to true otherwise return false
           set retbool to true
 
           *>declare #type as type Type = null
 
           *>declare publicKey = certificate::GetPublicKeyString
           *> Check public key if matche
           *> set #type = certificate::GetType
           *> declare p = #type::GetProperty("Thumbprint")
           *> declare thumbPrint = p::GetValue(certificate)::ToString
           goback.
       end method.
       end class.


Hi,

Can any advise how to convert below to Visual Cobol?

using System;

using System.IO;

using System.Net;

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;

 

namespace ConnectToFtpDemo

{

    class Program

    {

        static void Main(string[] args)

        {

            try

            {

                FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp:///testFileUpload.txt"); 

                request.Method = WebRequestMethods.Ftp.UploadFile; 

                request.Credentials = new NetworkCredential("Username", "Password");

                request.EnableSsl = true;

                ServicePointManager.ServerCertificateValidationCallback = ServicePointManager_ServerCertificateValidationCallback;

 

                long bytesSent = 0;

                using (Stream requestStream = request.GetRequestStream())

                using (FileStream uploadFileStream = File.OpenRead("C:\\\\Test\\\\test.txt"))

                {

                    uploadFileStream.CopyTo(requestStream);

                    bytesSent = uploadFileStream.Position;

                }

 

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex);

            }

 

            Console.ReadLine();

        }

 

 

        private static bool ServicePointManager_ServerCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)

        {

            //TODO: Logic to determine if certificate sent by server on connection is valid if it is return to true otherwise return false

            return true;

 

            //Type type = null;

 

            //var publicKey = certificate.GetPublicKeyString();

            //// Check public key if matche

            //type = certificate.GetType();

            //var p = type.GetProperty("Thumbprint");

            //var thumbPrint = p.GetValue(certificate)?.ToString();

           

 

        }

    }

}

Thanks for the quick reply Chris, Ill give it a go