View Single Post
  #2  
Old 03-02-2012, 01:44 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 920
Hi Tom,

The VRALib Connection object's Connect() method does not operate the same way as the SFXCL command line parser does.

The VRALib's Connection object provided a Connect() call for which the first parameter is only a hostname. If the Connection object's Hostname, Username, and Password properties have all been set before hand, you simply call Connect() with an empty string as the first parameter and false as the second parameter.

In your specific case, there's no such host named "sftp://username:passwordBetterThanThis@Server.IP.Address.Here", which explains why the VRALib Connection object's Connect() method is failing.

I'm including sample code of a C# console app that exemplifies how to accomplish a download operation similar to what you're trying.

Does this example show you how to properly call Connect() after setting the properties for Hostname, Username, Password, etc.?

Code:
using System;

namespace VRALibDownloadExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // For evaluation of VRALib, this code is needed; it does not cause any problems
            // for license/registered VRALib installations, so it can be left in place even
            // after you license VRALib:
            var objLicense = new vralib.License();
            string strEvalLeft = objLicense.AcceptEvaluationLicense();
            if (strEvalLeft.Contains(@"days remaining"))
                Console.WriteLine(strEvalLeft);

            // Create a VRAlib Connection object we'll use to control
            // the process of connecting via SSH to the remote system
            vralib.Connection objConn = new vralib.Connection();

            // Enable debug logging for assisting troubleshooting efforts
            objConn.DebugLogFile = @"C:\##vralib-Download-Dbg-Log.txt";
            objConn.DebugLevel = 5;
            
            objConn.Hostname = @"192.168.232.149";
            objConn.Port = 22;
            objConn.Username = @"user";

            // For public/private key authentication, use this (obviously, you'll
            // need to create two variables -- PrivateKeyPath, which contains the full
            // path to the private/public key file; and PrivateKeyPassphrase, which
            // contains the passphrase used to unlock/decrypt the private key for use.
            // Consult the VRALib documenation or more information.
            // objConn.SetPrivateKeyFile(PrivateKeyPath, PrivateKeyPassphrase);

            // Otherwise, just use plain old password auth
            objConn.Password = @"p4$$w0rd";

            // Now Connect to the remote system.  Wrap this in a try/catch block to
            // handle any connection failures "gracefully":
            Console.WriteLine("Connecting to " + objConn.Hostname + ":" + objConn.Port + "...");
            try
            {
                // When the Connection object has all the necessary connection info
                // already set in the form of properties (e.g. objConn.Hostname,
                // objConn.Username, objConn.Password, etc.), all that is needed is to call
                // Connect with an empty string as the first param, and 'false' as the second
                // param (StartAllForwards is a setting that doesn't apply to file transfer
                // connections).  See the VRALib help documentation .chm file for additional
                // details about the Connection object's Connect() method.
                objConn.Connect("", true);
            }
            catch (System.Runtime.InteropServices.COMException objException)
            {
                Console.WriteLine("Failed to connect:\r\n" + objException.ToString());
                Console.WriteLine("Press any key to continue.");
                Console.ReadKey();
                System.Environment.ExitCode = objException.ErrorCode;
                return;
            }
            
            Console.WriteLine(
                "Connected and authenticated to " + objConn.Hostname +
                " (" + objConn.RemoteIdentString + ")");

            // Get a reference to a file system object for the remote host
            vralib.IFileSystemObject objRemoteFS = objConn.FileSystemObject;

            // Download remote files (*.txt) to a local folder (C:\Temp\Incoming\)
            string strSrc = "*.txt";
            string strDst = @"C:\Temp\Incoming\";
            Console.WriteLine(@"Downloading '" + strSrc + "' from " + 
                objConn.Hostname + " to '" + strDst + "'");
            try
            {
                objRemoteFS.Get(strSrc, strDst);
            }
            catch (System.Runtime.InteropServices.COMException objException)
            {
                Console.WriteLine("Transfer failed:\r\n" + objException.ToString());
                Console.WriteLine("Press any key to continue.");
                Console.ReadKey();
                System.Environment.ExitCode = objException.ErrorCode;
                return;
            }
            catch (System.IO.FileNotFoundException objException)
            {
                Console.WriteLine("Transfer failed:\r\n" + objException.ToString());
                Console.WriteLine("Press any key to continue.");
                Console.ReadKey();
                System.Environment.ExitCode = 2;
                return;
            }
            catch (Exception objException)
            {
                Console.WriteLine("Transfer failed:\r\n" + objException.ToString());
                Console.WriteLine("Press any key to continue.");
                Console.ReadKey();
                System.Environment.ExitCode = -9999999;
                return;
            }

            Console.WriteLine("Transfer succeeded.\r\n\r\nPress any key to contine.");
            Console.ReadKey();
        }
    }
}
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote