Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
1.3k views
in General by (450 points)
I have a sandbox console app that I use to test EnterpriseDT things on, before I make them to our main applications. I can't seem to get the Logger to work right. could someone please tell me what I'm doing wrong? Isn't the logger supposed to log events as they happen? Do I need to do something to attach the logger to the SSHFTPClient?

I blanked out the software's key since I am posting this public.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Configuration;

using EnterpriseDT;
using EnterpriseDT.Net.Ftp;
using EnterpriseDT.Net.Ftp.Ssl;
using EnterpriseDT.Net.Ssh;
using EnterpriseDT.Net.Ftp.Ssh;
using EnterpriseDT.Net.Ssh.Routrek.PKI;
using EnterpriseDT.Util.Debug;

namespace ConsoleSandbox
{
    public class FTPTest
    {
        // Try using this to test:  http://www.techrepublic.com/blog/tr-dojo/set-up-a-free-ssh-server-on-windows-7-with-freesshd/
        // EnterpriseDT Documentation: http://www.enterprisedt.com/products/edtftpnetpro/overview.html
        // Code example from forum: http://www.enterprisedt.com/forums/viewtopic.php?p=12493&highlight=ssh+upload#12493
        private LocalFileLogger logger = new LocalFileLogger();
        private bool transferStarted = false;
        private bool transferComplete = false;
        private bool transferCancelled = false;

        public FTPTest()
        {
            Console.WriteLine("Testing FTPTest class");
            logger.LogPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString().TrimEnd('\\') + String.Format("\\SSHTestLogFile{0:yyyyMMddHHmm}.txt", DateTime.Now);
        }
        #region Accessors


        #endregion // Accessors

        #region Methods

        public void SshTest()
        {
            Console.WriteLine("Testing SshTest Method");

            string FTPLogFile = String.Format("{0}\\FTPLogFile.txt", System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).TrimEnd('/').TrimEnd('\\'));

            EnterpriseDT.Util.Debug.Logger.ClearAppenders();
            EnterpriseDT.Util.Debug.Logger.AddAppender(new EnterpriseDT.Util.Debug.RollingFileAppender(FTPLogFile, 5000000, 10));
            EnterpriseDT.Util.Debug.Logger log = EnterpriseDT.Util.Debug.Logger.GetLogger("SSHFTPClient");

            EnterpriseDT.Net.Ftp.Ssh.SSHFTPClient sshConnection = new EnterpriseDT.Net.Ftp.Ssh.SSHFTPClient();
            sshConnection.LicenseKey = "xxxxxxxxxxxxxxxxxxx";
            sshConnection.LicenseOwner = "xxxxxxxxxxxxxxxx";

            sshConnection.TransferStartedEx += new TransferHandler(sshConnection_TransferStartedEx);
            sshConnection.TransferCompleteEx += new TransferHandler(sshConnection_TransferCompleteEx);
            sshConnection.TransferCancelled += new TransferHandler(sshConnection_TransferCancelled);                    

            string knownHostsFilePath = ConfigurationManager.AppSettings["KnownHostsFilePath"]; // @"U:\Users\bmackenzie\Documents\Sandbox\KnownHostsFiles\KnownHosts.txt"; //

            sshConnection.ControlPort = Int32.Parse(ConfigurationManager.AppSettings["ControlPort"]); // 22; //
            sshConnection.RemoteHost = ConfigurationManager.AppSettings["RemoteHost"]; // "10.226.6.174"; //
            sshConnection.UserName = ConfigurationManager.AppSettings["UserName"]; // "sshtest"; //
            sshConnection.Password = ConfigurationManager.AppSettings["UserPassword"]; // "sshtest"; //
            sshConnection.CloseStreamsAfterTransfer = Boolean.Parse(ConfigurationManager.AppSettings["CloseStreamsAfterTransfer"]); // true; //
            
            // SSHCompressionAlgorithm enums: None = 1, Zlib = 2, All = 3
            sshConnection.PreferredCompressionAlgorithms = (SSHCompressionAlgorithm)(Int32.Parse(ConfigurationManager.AppSettings["PreferredCompressionAlgorithms"])); // SSHCompressionAlgorithm.Zlib; // 
            
            FTPTransferType transferType = FTPTransferType.ASCII;
            
            // sshAuthenticationType Enums: None = 1, PublicKey = 2, Password = 3, KeyboardInteractive = 4, PublicKeyAndPassword = 5
            sshConnection.AuthenticationMethod = (AuthenticationType)(Int32.Parse(ConfigurationManager.AppSettings["SshAuthenticationType"])); // AuthenticationType.PublicKey; //
            
            // On my sample SSH server, I set the home folder to: C:\ProductionSupportFiles\FTPTest\SSHTest\Public\
            string workingDirectory = ConfigurationManager.AppSettings["TargetServerWorkingUploadFolder"]; //@"\Upload\iPayIberia";
            string filePath = ConfigurationManager.AppSettings["LocalServerFileToUpload"]; // @"C:\ProductionSupportFiles\iPass DLLs\iPayNet\IberiaBank\Iberia_Pay_20140113";
            string remoteFileName = ConfigurationManager.AppSettings["TargetServerFilenameRename"]; // "TestRemoteFile Name";
            string sshPublicKeyFilePath = "";

            // None = 0, Automatic = 1, AutomaticNoNameCheck = 2, Callback = 3. Automatic is the default.
            sshConnection.ServerValidation = (SecureFTPServerValidationType)(Int32.Parse(ConfigurationManager.AppSettings["SshServerValidationType"])); // SecureFTPServerValidationType.None;
            
            // SecureFTPCompatibilityFlags enum: Standard = 0, SSLDisableControlClosure = 1, SSLDisableDataClosure = 2, SSLDisableControlWaitOnClose = 4, SSLDisableDataWaitOnClose = 8, SSLDisableControlWaitOnShutdownSSL = 16, SSHDisableChmodAfterPut = 32768
            //SecureFTPCompatibilityFlags sftpCompatibilityFlags = SecureFTPCompatibilityFlags.Standard;
            //sshConnection.ServerCompatibility = sftpCompatibilityFlags;

            if (sshConnection.AuthenticationMethod == AuthenticationType.PublicKey || sshConnection.AuthenticationMethod == AuthenticationType.PublicKeyAndPassword)
            {
                // Public Key path will be used

2 Answers

0 votes
by (161k points)
Try setting the logging level - I can't see it set in your code.
0 votes
by (450 points)
That did it. Thank you so much! This will help troubleshooting our application SO much!

Categories

...