Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Convert a C# WinSCP program to C++/CLI

Convert a C# WinSCP program to C++/CLI

Scheduled Pinned Locked Moved Managed C++/CLI
csharphelptutorialc++dotnet
5 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    biop codeproject
    wrote on last edited by
    #1

    Please help! Even I am experienced in C++ and C#, I am new to C++/CLI. I have written a simple C# program using WinSCP library. I know how to do it in C# as there is already an example (http://winscp.net/eng/docs/library#csharp[^]) I try to convert but I do not get any success.

    #using "WinSCPnet.dll"
    using namespace System;

    int main(array ^args)
    {
    try
    {
    Console::WriteLine("Staring...");

       WinSCP::SessionOptons ^ sftpSessionOptions = gcnew
          WinSCP::SessionOptions::SessionOptions (
             WinSCP::SessionOptions::Protocol = 
                   WinSCP::Protocol::Sftp,
                   ...
          );
    

    ...
    }

    But I get this error: Error c2061: syntax error: identifer '{ctor}' why? Please help in the translation. Yes I have made sure it compiles with '/clr' option.

    L S 2 Replies Last reply
    0
    • B biop codeproject

      Please help! Even I am experienced in C++ and C#, I am new to C++/CLI. I have written a simple C# program using WinSCP library. I know how to do it in C# as there is already an example (http://winscp.net/eng/docs/library#csharp[^]) I try to convert but I do not get any success.

      #using "WinSCPnet.dll"
      using namespace System;

      int main(array ^args)
      {
      try
      {
      Console::WriteLine("Staring...");

         WinSCP::SessionOptons ^ sftpSessionOptions = gcnew
            WinSCP::SessionOptions::SessionOptions (
               WinSCP::SessionOptions::Protocol = 
                     WinSCP::Protocol::Sftp,
                     ...
            );
      

      ...
      }

      But I get this error: Error c2061: syntax error: identifer '{ctor}' why? Please help in the translation. Yes I have made sure it compiles with '/clr' option.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You are passing parameters to a parameterless constructor; see http://winscp.net/eng/docs/library_sessionoptions#constructors[^]. You need to create the object and then set the properties separately.

      B 1 Reply Last reply
      0
      • B biop codeproject

        Please help! Even I am experienced in C++ and C#, I am new to C++/CLI. I have written a simple C# program using WinSCP library. I know how to do it in C# as there is already an example (http://winscp.net/eng/docs/library#csharp[^]) I try to convert but I do not get any success.

        #using "WinSCPnet.dll"
        using namespace System;

        int main(array ^args)
        {
        try
        {
        Console::WriteLine("Staring...");

           WinSCP::SessionOptons ^ sftpSessionOptions = gcnew
              WinSCP::SessionOptions::SessionOptions (
                 WinSCP::SessionOptions::Protocol = 
                       WinSCP::Protocol::Sftp,
                       ...
              );
        

        ...
        }

        But I get this error: Error c2061: syntax error: identifer '{ctor}' why? Please help in the translation. Yes I have made sure it compiles with '/clr' option.

        S Offline
        S Offline
        sunshine work
        wrote on last edited by
        #3

        Hello,.. Hey i dont know how u willtake my suggestion but , i have an idea for u Use C# to C++ convertor.. it may help you..

        int Example::Main()
        {
        try
        {
        // Setup session options
        SessionOptions ^sessionOptions = gcnew SessionOptions {Protocol = Protocol::Sftp, HostName = "example.com", UserName = "user", Password = "mypassword", SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"};

         using (Session session = new Session())
            Session ^session = gcnew Session();
            try
            {
                // Connect
                session->Open(sessionOptions);
        
                // Upload files
                TransferOptions ^transferOptions = gcnew TransferOptions();
                transferOptions->TransferMode = TransferMode::Binary;
        
                TransferOperationResult ^transferResult;
                transferResult = session->PutFiles("d:\\\\toupload\\\\\*", "/home/user/", false, transferOptions);
        
                // Throw on any error
                transferResult->Check();
        
                // Print results
                for each (TransferEventArgs ^transfer in transferResult->Transfers)
                {
                    Console::WriteLine("Upload of {0} succeeded", transfer->FileName);
                }
            }
            finally
            {
                delete session;
            }
        
            return 0;
        }
        catch (Exception ^e)
        {
            Console::WriteLine("Error: {0}", e);
            return 1;
        }
        

        This ur sample C# code to C++/CLI.

        B 1 Reply Last reply
        0
        • S sunshine work

          Hello,.. Hey i dont know how u willtake my suggestion but , i have an idea for u Use C# to C++ convertor.. it may help you..

          int Example::Main()
          {
          try
          {
          // Setup session options
          SessionOptions ^sessionOptions = gcnew SessionOptions {Protocol = Protocol::Sftp, HostName = "example.com", UserName = "user", Password = "mypassword", SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"};

           using (Session session = new Session())
              Session ^session = gcnew Session();
              try
              {
                  // Connect
                  session->Open(sessionOptions);
          
                  // Upload files
                  TransferOptions ^transferOptions = gcnew TransferOptions();
                  transferOptions->TransferMode = TransferMode::Binary;
          
                  TransferOperationResult ^transferResult;
                  transferResult = session->PutFiles("d:\\\\toupload\\\\\*", "/home/user/", false, transferOptions);
          
                  // Throw on any error
                  transferResult->Check();
          
                  // Print results
                  for each (TransferEventArgs ^transfer in transferResult->Transfers)
                  {
                      Console::WriteLine("Upload of {0} succeeded", transfer->FileName);
                  }
              }
              finally
              {
                  delete session;
              }
          
              return 0;
          }
          catch (Exception ^e)
          {
              Console::WriteLine("Error: {0}", e);
              return 1;
          }
          

          This ur sample C# code to C++/CLI.

          B Offline
          B Offline
          biop codeproject
          wrote on last edited by
          #4

          I try that converter, but when I compile, there are problems. Thanks for the suggestion. :)

          1 Reply Last reply
          0
          • L Lost User

            You are passing parameters to a parameterless constructor; see http://winscp.net/eng/docs/library_sessionoptions#constructors[^]. You need to create the object and then set the properties separately.

            B Offline
            B Offline
            biop codeproject
            wrote on last edited by
            #5

            Richard, Thanks for your help. I get it. The thing is when I mouse over the new SessionOptions in this line in the C# program,

            SessionOptions sessionOptions = new SessionOptions {
            Protocol = Protocol.Sftp,

            I see SessionOptions.SessionOptions(). With that in mind, when I do the C++ program, I convert that line to:

            WinSCP::SessionOptions ^ sftpOptions = gcnew
            WinSCP::SessionOptions::SessionOptions()
            sftpOptions->Protocol = WinSCP::Protocol::Sftp;

            As you can see, that (WinSCP::SessionOptions::SessionOptions()) is not a valid call. I change that to gcnew WinSCP::SessionOptions() and it works! Thanks.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups