Exemple #1
0
        private static void DoFeatures(FTPSClient client)
        {
            IList <string> features = client.GetFeatures();

            Console.WriteLine();

            if (features == null)
            {
                Console.WriteLine("The FEAT command is not supported by the server");
            }
            else
            {
                Console.WriteLine("Features:");
                Console.WriteLine();

                foreach (string feature in features)
                {
                    Console.WriteLine(feature);
                }
            }
        }
Exemple #2
0
        public static TransactionLogs ExtractAMSData(FTPSClient client, string directory, TransactionLogs tl)
        {
            TransactionLogs amstl = new TransactionLogs();

            amstl.TimeRecorded = tl.TimeRecorded;
            amstl.SaleNo       = tl.SaleNo;
            amstl.Filename     = tl.Filename;

            try
            {
                // Download file
                string tempFile = directory + "temp";
                client.GetFile(tl.Filename, tempFile);
                // Extract sale number and description
                XmlTextReader reader = new XmlTextReader(tempFile);

                amstl = ExtractAMSXMLData(tempFile, tl);

                // Delete temp file
                File.Delete(tempFile);
            }
            catch (FTPCommandException fce)
            {
                LogMsg("FTP Command problem " + fce.InnerException + " Error Code " + fce.ErrorCode + " File " + tl.Filename);
//                MessageBox.Show("FTP Command problem " + fce.InnerException);
            }
            catch (FTPException fe)
            {
                LogMsg("FTP problem " + fe.InnerException);
//                MessageBox.Show("FTP problem " + fe.InnerException);
            }


            catch (IOException ie)
            {
                LogMsg("IO problem " + ie.InnerException);
            }

            return(amstl);
        }
Exemple #3
0
        private static void WriteSslStatus(FTPSClient client)
        {
            if (options.verbose)
            {
                string sslSupportDesc = null;

                if ((client.SslSupportCurrentMode & ESSLSupportMode.CredentialsRequested) == ESSLSupportMode.CredentialsRequested)
                {
                    sslSupportDesc = "Credentials";
                }
                if ((client.SslSupportCurrentMode & ESSLSupportMode.ControlChannelRequested) == ESSLSupportMode.ControlChannelRequested)
                {
                    sslSupportDesc += ", Commands";
                }

                if ((client.SslSupportCurrentMode & ESSLSupportMode.DataChannelRequested) == ESSLSupportMode.DataChannelRequested)
                {
                    if (sslSupportDesc != null)
                    {
                        sslSupportDesc += ", ";
                    }
                    sslSupportDesc += "Data";
                }

                if (sslSupportDesc == null)
                {
                    sslSupportDesc = "None";
                }

                Console.WriteLine();
                Console.WriteLine("SSL/TLS support: " + sslSupportDesc);

                SslInfo sslInfo = client.SslInfo;
                if (sslInfo != null)
                {
                    Console.WriteLine("SSL/TLS Info: " + sslInfo.ToString());
                }
            }
        }
Exemple #4
0
        private static void DoList(FTPSClient client)
        {
            string remoteDirName = null;

            if (commandArguments.Count > 0)
            {
                remoteDirName = NormalizeRemotePath(commandArguments[0]);
            }
            else
            {
                remoteDirName = client.GetCurrentDirectory();
            }

            Console.WriteLine();
            Console.WriteLine("Remote directory: " + remoteDirName);

            // Get the dirList before the WriteLine in order to avoid writing an empty newline in case of exceptions
            string dirList = client.GetDirectoryListUnparsed(remoteDirName);

            Console.WriteLine();
            Console.WriteLine(dirList);
        }
        private async Task SendByFtps(FtpMessage ftpMessage)
        {
            var host     = ftpMessage.Configuration.FtpHost;
            var path     = ftpMessage.Filename;
            var username = ftpMessage.Configuration.Username;
            var password = ftpMessage.Configuration.Password;
            var port     = ftpMessage.Configuration.FtpPort;


            using (var client = new FTPSClient())
            {
                client.Connect(host.Host,
                               new NetworkCredential(username, password),
                               ESSLSupportMode.CredentialsRequired |
                               ESSLSupportMode.DataChannelRequested);

                var ftps = client.PutFile(path);

                await ftps.WriteAsync(ftpMessage.Data, 0, ftpMessage.Data.Length);

                ftps.Close();
            }
        }
Exemple #6
0
        public void CreateDirectory(string newDirectory)
        {
            var ftp = new FTPSClient();

            try
            {
                ftp.Connect(this.host, new NetworkCredential(this.user, this.password), ESSLSupportMode.ClearText);
                ftp.SetTransferMode(this.UseBinary ? ETransferMode.Binary : ETransferMode.ASCII);

                ftp.MakeDir(newDirectory);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (ftp != null)
                {
                    ftp.Close();
                    ftp.Dispose();
                }
            }
        }
Exemple #7
0
        private static void DoExportSslServerCert(FTPSClient client)
        {
            if (client.SslSupportCurrentMode == ESSLSupportMode.ClearText)
            {
                throw new Exception("The FTP connection is not encrypted");
            }

            X509Certificate cert = client.RemoteCertificate;

            if (cert == null)
            {
                throw new Exception("No remote SSL/TLS X.509 certificate available");
            }

            X509ContentType exportX509ContentType = X509ContentType.Cert;

            switch (options.sslCertExportFormat)
            {
            case EX509CertificateExportFormats.Cert:
                exportX509ContentType = X509ContentType.Cert;
                break;

            case EX509CertificateExportFormats.SerializedCert:
                exportX509ContentType = X509ContentType.SerializedCert;
                break;

            case EX509CertificateExportFormats.Pkcs12:
                exportX509ContentType = X509ContentType.Pkcs12;
                break;
            }

            byte[] exportedCert = cert.Export(exportX509ContentType);

            using (Stream s = File.Create(commandArguments[0]))
                s.Write(exportedCert, 0, exportedCert.Length);
        }
Exemple #8
0
 private static void DoAppendFile(FTPSClient client)
 {
     string localPathName = commandArguments[0];
     string remotePathName = GetRemotePathName(localPathName);
     client.AppendFile(localPathName, remotePathName, new FileTransferCallback(TransferCallback));
 }
Exemple #9
0
 private static void DoRemoveDir(FTPSClient client)
 {
     client.RemoveDir(NormalizeRemotePath(commandArguments[0]));
 }
Exemple #10
0
 private static void DoDeleteFile(FTPSClient client)
 {
     client.DeleteFile(NormalizeRemotePath(commandArguments[0]));
 }
Exemple #11
0
        private static void DoConnect(FTPSClient client)
        {
            WriteCredentialsEncryptionWarning();

            CheckPassword();

            int port = options.port;
            if (port == 0)
                port = (options.sslRequestSupportMode & ESSLSupportMode.Implicit) == ESSLSupportMode.Implicit ? 990 : 21;

            NetworkCredential credential = null;
            if (options.userName != null && options.userName.Length > 0)
                credential = new NetworkCredential(options.userName, options.password);

            X509Certificate x509ClientCert = null;
            if (options.sslClientCertPath != null)
                x509ClientCert = X509Certificate.CreateFromCertFile(options.sslClientCertPath);

            client.Connect(options.hostName, port,
                           credential,
                           options.sslRequestSupportMode,
                           new RemoteCertificateValidationCallback(ValidateTestServerCertificate),
                           x509ClientCert,
                           options.sslMinKeyExchangeAlgStrength,
                           options.sslMinCipherAlgStrength,
                           options.sslMinHashAlgStrength,
                           options.timeout * 1000,
                           options.useCtrlEndPointAddressForData,
                           options.dataConnectionMode);

            // client.Connect already sets binary by default
            if (options.transferMode != ETransferMode.Binary)
                client.SetTransferMode(options.transferMode);

            WriteConnectionInfo(client);

            WriteSslStatus(client);
        }
Exemple #12
0
        private static void WriteConnectionInfo(FTPSClient client)
        {
            if (options.verbose)
            {
                Console.WriteLine();
                Console.WriteLine("Banner message:");
                Console.WriteLine();
                Console.WriteLine(client.BannerMessage);
                Console.WriteLine();

                Console.WriteLine("Welcome message:");
                Console.WriteLine();
                Console.WriteLine(client.WelcomeMessage);
                Console.WriteLine();

                Console.WriteLine("Text encoding: " + client.TextEncoding.ToString());
                Console.WriteLine("Transfer mode: " + client.TransferMode.ToString());
            }
        }
Exemple #13
0
 /// <summary>
 /// Initialises a new instance of the <see cref="FtpQueueClient"/> class.
 /// </summary>
 public FtpQueueClient()
 {
     this._ftpClient = new FTPSClient();
 }
Exemple #14
0
        private static void DoList(FTPSClient client)
        {
            string remoteDirName = null;
            if (commandArguments.Count > 0)
                remoteDirName = NormalizeRemotePath(commandArguments[0]);
            else
                remoteDirName = client.GetCurrentDirectory();

            Console.WriteLine();
            Console.WriteLine("Remote directory: " + remoteDirName);

            // Get the dirList before the WriteLine in order to avoid writing an empty newline in case of exceptions
            string dirList = client.GetDirectoryListUnparsed(remoteDirName);
            Console.WriteLine();
            Console.WriteLine(dirList);
        }
Exemple #15
0
        private static void DoPut(FTPSClient client)
        {
            string localPathPattern = commandArguments[0];

            if (IsWildCardPath(localPathPattern))
                DoWildCardPut(client, localPathPattern);
            else
                DoSingleFilePut(client, localPathPattern);
        }
Exemple #16
0
        private static void DoFeatures(FTPSClient client)
        {
            IList<string> features = client.GetFeatures();

            Console.WriteLine();

            if(features == null)
                Console.WriteLine("The FEAT command is not supported by the server");
            else
            {
                Console.WriteLine("Features:");
                Console.WriteLine();

                foreach (string feature in features)
                    Console.WriteLine(feature);
            }
        }
Exemple #17
0
        private static void DoGet(FTPSClient client)
        {
            string remotePathPattern = commandArguments[0];

            if (IsWildCardPath(remotePathPattern))
                DoWildCardGet(client, remotePathPattern);
            else
                DoSingleFileGet(client, remotePathPattern);
        }
Exemple #18
0
        private static void DoExportSslServerCert(FTPSClient client)
        {
            if (client.SslSupportCurrentMode == ESSLSupportMode.ClearText)
                throw new Exception("The FTP connection is not encrypted");

            X509Certificate cert = client.RemoteCertificate;
            if (cert == null)
                throw new Exception("No remote SSL/TLS X.509 certificate available");

            X509ContentType exportX509ContentType = X509ContentType.Cert;
            switch (options.sslCertExportFormat)
            {
                case EX509CertificateExportFormats.Cert:
                    exportX509ContentType = X509ContentType.Cert;
                    break;
                case EX509CertificateExportFormats.SerializedCert:
                    exportX509ContentType = X509ContentType.SerializedCert;
                    break;
                case EX509CertificateExportFormats.Pkcs12:
                    exportX509ContentType = X509ContentType.Pkcs12;
                    break;
            }

            byte[] exportedCert = cert.Export(exportX509ContentType);

            using (Stream s = File.Create(commandArguments[0]))
                s.Write(exportedCert, 0, exportedCert.Length);
        }
Exemple #19
0
 private static void DoDeleteFile(FTPSClient client)
 {
     client.DeleteFile(NormalizeRemotePath(commandArguments[0]));
 }
Exemple #20
0
        private static void DoCustomCommand(FTPSClient client)
        {
            FTPReply reply = client.SendCustomCommand(commandArguments[0]);

            Console.WriteLine("Server reply: " + reply.ToString());
        }
Exemple #21
0
 private static void InitLogFile(FTPSClient client)
 {
     if (options.logFileName != null)
     {
         swLog = new StreamWriter(options.logFileName);
         client.LogCommand += new LogCommandEventHandler(client_LogCommand);
         client.LogServerReply += new LogServerReplyEventHandler(client_LogServerReply);
     }
 }
Exemple #22
0
        private static void DoPutUniqueFile(FTPSClient client)
        {
            string localPathName = commandArguments[0];

            if(commandArguments.Count > 1)
            {
                string remoteDirName = NormalizeRemotePath(commandArguments[1]);
                client.SetCurrentDirectory(remoteDirName);
            }

            string remoteFileName;
            client.PutUniqueFile(localPathName, out remoteFileName, new FileTransferCallback(TransferCallback));

            Console.WriteLine("Unique file uploaded. File name: \"" + remoteFileName + "\"");
        }
Exemple #23
0
 private static void TransferCallback(FTPSClient sender, ETransferActions action, string localObjectName, string remoteObjectName, ulong fileTransmittedBytes, ulong? fileTransferSize, ref bool cancel)
 {
     switch (action)
     {
         case ETransferActions.FileDownloaded:
         case ETransferActions.FileUploaded:
             OnFileTransferCompleted(fileTransmittedBytes, fileTransferSize);
             break;
         case ETransferActions.FileDownloadingStatus:
         case ETransferActions.FileUploadingStatus:
             OnFileTransferStatus(action, localObjectName, remoteObjectName, fileTransmittedBytes, fileTransferSize);
             break;
         case ETransferActions.RemoteDirectoryCreated:
             if (options.verbose)
             {
                 Console.WriteLine();
                 Console.WriteLine("Remote directory created: " + remoteObjectName);
             }
             break;
         case ETransferActions.LocalDirectoryCreated:
             if (options.verbose)
             {
                 Console.WriteLine();
                 Console.WriteLine("Local directory created: " + localObjectName);
             }
             break;
     }
 }
Exemple #24
0
        public static bool GetCurrentRecords(string Server, string SignalId, string User, string Password,
                                             string LocalDir, string RemoteDir, bool DeleteFilesAfterFTP, int SNMPRetry, int SNMPTimeout, int SNMPPort,
                                             bool ImportAfterFTP, bool activemode, int waitbetweenrecords, BulkCopyOptions Options,
                                             int FTPTimeout) //, CancellationToken Token)
        {
            var recordsComplete = false;

            var errorRepository = ApplicationEventRepositoryFactory.Create();


            //Initialize the FTP object
            var RetryFiles = new List <string>();
            var FTP        = new FTPSClient();
            var Cred       = new NetworkCredential(User, Password);
            var SSLMode    = ESSLSupportMode.ClearText;
            var DM         = EDataConnectionMode.Passive;

            if (activemode)
            {
                DM = EDataConnectionMode.Active;
            }


            var connected   = false;
            var FilePattern = ".dat";


            try
            {
                try
                {
                    var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
                    var token2      = tokenSource.Token;

                    Task task = Task.Factory.StartNew(
                        () => FTP.Connect(Server, 21, Cred, SSLMode, null, null, 0, 0, 0, FTPTimeout, true, DM)
                        , token2);

                    task.Wait(token2);

                    if (token2.IsCancellationRequested)
                    {
                        token2.ThrowIfCancellationRequested();
                    }
                }
                catch (AggregateException)
                {
                    errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "ConnectToController",
                                             ApplicationEvent.SeverityLevels.Medium, "The connection task timed out for signal " + Server);
                }
                {
                    Console.WriteLine("Connection Failure");
                }

                connected = true;
            }
            //If there is an error, Print the error and go on to the next file.
            catch (FTPException ex)
            {
                errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "ConnectToController",
                                         ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message);
                Console.WriteLine(ex.Message);
            }
            catch (AggregateException)
            {
                Console.WriteLine("Connection Failure");
            }

            catch (SocketException ex)
            {
                errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "ConnectToController",
                                         ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message);
                Console.WriteLine(ex.Message);
            }
            catch (IOException ex)
            {
                errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "ConnectToController",
                                         ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message);
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "ConnectToController",
                                         ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message);
                Console.WriteLine(ex.Message);
            }

            if (connected)
            {
                try
                {
                    //if (Token.IsCancellationRequested)
                    //{
                    //    Token.ThrowIfCancellationRequested();
                    //}

                    FTP.SetCurrentDirectory("..");


                    FTP.SetCurrentDirectory(RemoteDir);
                }
                catch (AggregateException)
                {
                    Console.WriteLine("Connection Failure for " + Server);
                }

                catch (Exception ex)
                {
                    errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "GetCurrentRecords",
                                             ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message);
                    Console.WriteLine(ex.Message);
                }


                try
                {
                    IList <DirectoryListItem> RemoteFiles = null;
                    var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
                    var token       = tokenSource.Token;

                    Task task = Task.Factory.StartNew(() => RemoteFiles = FTP.GetDirectoryList(RemoteDir)
                                                      , token);

                    task.Wait(token);

                    if (token.IsCancellationRequested)
                    {
                        token.ThrowIfCancellationRequested();
                    }

                    var RetrievedFiles = new List <string>();


                    //errorRepository.QuickAdd("FTPFromAllcontrollers","Signal", "GetFTPFileList", Models.ApplicationEvent.SeverityLevels.Information, "Retrevied File list from " + Server);
                    if (RemoteFiles != null)
                    {
                        foreach (var FTPFile in RemoteFiles)
                        {
                            if (!FTPFile.IsDirectory && FTPFile.Name.Contains(FilePattern))
                            {
                                try
                                {
                                    //if (Token.IsCancellationRequested)
                                    //{
                                    //    Token.ThrowIfCancellationRequested();
                                    //}

                                    //If there are no errors, get the file, and add the filename to the retrieved files array for deletion later


                                    var token2 = tokenSource.Token;

                                    var task2 = Task.Factory.StartNew(
                                        () => TransferFiles(FTP, FTPFile.Name, LocalDir, RemoteDir, Server)
                                        , token2);

                                    task2.Wait(token2);

                                    if (token2.IsCancellationRequested)
                                    {
                                        token2.ThrowIfCancellationRequested();
                                    }
                                    else
                                    {
                                        RetrievedFiles.Add(FTPFile.Name);

                                        recordsComplete = true;
                                    }
                                }
                                //If there is an error, Print the error and try the file again.
                                catch (AggregateException)
                                {
                                    errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "TransferFiles",
                                                             ApplicationEvent.SeverityLevels.Medium, "Transfer Task Timed Out");
                                }
                                catch (Exception ex)
                                {
                                    var errorMessage = "Exception:" + ex.Message + " While Transfering file: " +
                                                       FTPFile + " from " + RemoteDir + " on " + Server + " to " +
                                                       LocalDir;
                                    Console.WriteLine(errorMessage);
                                    errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "TransferFiles",
                                                             ApplicationEvent.SeverityLevels.Medium, errorMessage);
                                    RetryFiles.Add(FTPFile.Name);
                                }
                                Thread.Sleep(waitbetweenrecords);
                            }
                        }
                    }

                    //Delete the files we downloaded.  We don't want ot have to deal with the file more than once.  If we delete the file form the controller once we capture it, it will reduce redundancy.


                    if (DeleteFilesAfterFTP)
                    {
                        DeleteFilesFromFTPServer(FTP, RetrievedFiles, waitbetweenrecords, RemoteDir,
                                                 Server); //, Token);
                    }
                }

                catch (Exception ex)
                {
                    errorRepository.QuickAdd("FTPFromAllcontrollers", "Signal", "RetrieveFiles",
                                             ApplicationEvent.SeverityLevels.Medium, Server + " " + ex.Message);
                    Console.WriteLine(ex.Message);
                }


                FTP.Close();
                FTP.Dispose();

                //**********************************************************
                //I don't think this is doing much good. -SJ 11-22-2016

                //Try to get the missing files again with a new FTP connection

                //if (RetryFiles.Count > 1)
                //{

                //    foreach (string FTPFile in RetryFiles)
                //    {
                //        try
                //        {

                //            Thread.Sleep(waitbetweenrecords);

                //            FTPSClient _FTP = new FTPSClient();
                //            _FTP.Connect(Server, 21, Cred, SSLMode, null, null, 0, 0, 0, 6000, false, DM);

                //            TransferFiles(_FTP, FTPFile, LocalDir, RemoteDir, Server);


                //            if (DeleteFilesAfterFTP)
                //            {
                //                try
                //                {
                //                    _FTP.DeleteFile(FTPFile);
                //                }
                //                catch (Exception ex)
                //                {
                //                    Console.WriteLine("Exception:" + ex.Message + " While Deleting file: " + FTPFile + " from " + RemoteDir + " on " + Server + " to " + LocalDir);

                //                }
                //            }
                //            _FTP.Close();
                //            _FTP.Dispose();


                //        }
                //        //If there is an error, Print the error and move on.
                //        catch (Exception ex1)
                //        {
                //            Console.WriteLine("Exception:" + ex1.Message + " While Transfering file: " + FTPFile + " from " + RemoteDir + " on " + Server + " to " + LocalDir);
                //        }

                //    }

                // }


                // RetryFiles.Clear();
                //**************************************

                //Turn Logging off.
                //The ASC3 controller stoploggin if the current file is removed.  to make sure logging comtinues, we must turn the loggin feature off on the
                //controller, then turn it back on.
                try
                {
                    TurnOffASC3LoggingOverSNMP(SNMPRetry, SNMPPort, SNMPTimeout, Server);

                    Thread.Sleep(SNMPTimeout);


                    TurnOnASC3LoggingOverSNMP(SNMPRetry, SNMPPort, SNMPTimeout, Server);
                }
                catch
                {
                }
            }
            return(recordsComplete);
        }
Exemple #25
0
        private static void WriteSslStatus(FTPSClient client)
        {
            if (options.verbose)
            {
                string sslSupportDesc = null;

                if ((client.SslSupportCurrentMode & ESSLSupportMode.CredentialsRequested) == ESSLSupportMode.CredentialsRequested)
                    sslSupportDesc = "Credentials";
                if ((client.SslSupportCurrentMode & ESSLSupportMode.ControlChannelRequested) == ESSLSupportMode.ControlChannelRequested)
                    sslSupportDesc += ", Commands";

                if ((client.SslSupportCurrentMode & ESSLSupportMode.DataChannelRequested) == ESSLSupportMode.DataChannelRequested)
                {
                    if (sslSupportDesc != null)
                        sslSupportDesc += ", ";
                    sslSupportDesc += "Data";
                }

                if (sslSupportDesc == null)
                    sslSupportDesc = "None";

                Console.WriteLine();
                Console.WriteLine("SSL/TLS support: " + sslSupportDesc);

                SslInfo sslInfo = client.SslInfo;
                if (sslInfo != null)
                {
                    Console.WriteLine("SSL/TLS Info: " + sslInfo.ToString());
                }
            }
        }
Exemple #26
0
        private static void DoCustomCommand(FTPSClient client)
        {
            FTPReply reply = client.SendCustomCommand(commandArguments[0]);

            Console.WriteLine("Server reply: " + reply.ToString());
        }
Exemple #27
0
 private static void DoRemoveDir(FTPSClient client)
 {
     client.RemoveDir(NormalizeRemotePath(commandArguments[0]));
 }
Exemple #28
0
        private static void DoCommands()
        {
            try
            {
                using (FTPSClient client = new FTPSClient())
                {
                    InitLogFile(client);

                    DoConnect(client);

                    if (options.listDirCmd)
                        DoList(client);

                    if (options.getCmd)
                        DoGet(client);

                    if (options.putCmd)
                        DoPut(client);

                    if (options.deleteFileCmd)
                        DoDeleteFile(client);

                    if (options.renameFileCmd)
                        DoRenameFile(client);

                    if (options.makeDirCmd)
                        DoMakeDir(client);

                    if (options.removeDirCmd)
                        DoRemoveDir(client);

                    if (options.putUniqueFileCmd)
                        DoPutUniqueFile(client);

                    if (options.putAppendFileCmd)
                        DoAppendFile(client);

                    if (options.sysCmd)
                        DoSys(client);

                    if (options.expCertCmd)
                        DoExportSslServerCert(client);

                    if (options.featuresCmd)
                        DoFeatures(client);

                    if (options.customCmd)
                        DoCustomCommand(client);

                    if (options.verbose)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Command completed");
                    }
                }
            }
            finally
            {
                if (swLog != null)
                {
                    swLog.Close();
                    swLog = null;
                }
            }
        }
Exemple #29
0
        private static void DoCommands()
        {
            try
            {
                using (FTPSClient client = new FTPSClient())
                {
                    InitLogFile(client);

                    DoConnect(client);

                    if (options.listDirCmd)
                    {
                        DoList(client);
                    }

                    if (options.getCmd)
                    {
                        DoGet(client);
                    }

                    if (options.putCmd)
                    {
                        DoPut(client);
                    }

                    if (options.deleteFileCmd)
                    {
                        DoDeleteFile(client);
                    }

                    if (options.renameFileCmd)
                    {
                        DoRenameFile(client);
                    }

                    if (options.makeDirCmd)
                    {
                        DoMakeDir(client);
                    }

                    if (options.removeDirCmd)
                    {
                        DoRemoveDir(client);
                    }

                    if (options.putUniqueFileCmd)
                    {
                        DoPutUniqueFile(client);
                    }

                    if (options.putAppendFileCmd)
                    {
                        DoAppendFile(client);
                    }

                    if (options.sysCmd)
                    {
                        DoSys(client);
                    }

                    if (options.expCertCmd)
                    {
                        DoExportSslServerCert(client);
                    }

                    if (options.featuresCmd)
                    {
                        DoFeatures(client);
                    }

                    if (options.customCmd)
                    {
                        DoCustomCommand(client);
                    }

                    if (options.verbose)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Command completed");
                    }
                }
            }
            finally
            {
                if (swLog != null)
                {
                    swLog.Close();
                    swLog = null;
                }
            }
        }
Exemple #30
0
 private static void DoRenameFile(FTPSClient client)
 {
     client.RenameFile(NormalizeRemotePath(commandArguments[0]),
                       NormalizeRemotePath(commandArguments[1]));
 }
Exemple #31
0
        internal static long GetLatestSaleNo()
        {
            string   Host     = null;
            Int32    Port     = 0;
            string   Username = null;
            string   Password = null;
            DateTime Latest   = Convert.ToDateTime("1/1/1970");

            Host     = "192.168.44.40";
            Username = "******";
            Password = "******";
            Port     = 990;

            long saleNo = 0;

            Console.WriteLine("Opening ftp connection");

            // Download the XML transcript and pop it into AMS...
            using (FTPSClient client = new FTPSClient())
            {
                try
                {
                    client.Connect(Host, Port,
                                   new NetworkCredential(Username,
                                                         Password),
                                   ESSLSupportMode.CredentialsRequired | ESSLSupportMode.DataChannelRequested | ESSLSupportMode.Implicit,
                                   new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications),
                                   new System.Security.Cryptography.X509Certificates.X509Certificate(),
                                   0, 0, 0, 60000, true);
                    LogMsg("GetLatestSaleNo - FTP Connected ");
                    Console.WriteLine("FTP connected");
                }
                catch (FTPCommandException fe)
                {
                    LogMsg(fe);
                    return(0);
                }
                catch (IOException ie)
                {
                    LogMsg(ie);
                    return(0);
                }
                catch (SocketException ie)
                {
                    LogMsg(ie);
                    return(0);
                }

                try
                {
                    // Change to Transaction log directory
                    String pwd = client.GetCurrentDirectory();
                    client.SetCurrentDirectory("TransactionLogs");
                }
                catch (FTPCommandException fe)
                {
                    LogMsg(fe);
                    return(0);
                }

                try
                {
                    {
                        Console.WriteLine("Find latest file");

                        // Find latest file
                        List <DirectoryListItem> ftpItems = client.GetDirectoryList().ToList();

                        string lastFile = "";
                        // Find latest file
                        foreach (DirectoryListItem FtpItem in ftpItems)
                        {
                            if (FtpItem.Name.CompareTo(lastFile) > 0)
                            {
                                lastFile = FtpItem.Name;
                            }
                        }

                        Console.WriteLine("GetLatestSaleNo " + lastFile);
                        if (lastFile != null)
                        {
                            saleNo = Convert.ToInt64(lastFile.Substring(0, 4));
                        }

                        LogMsg("GetLatestSaleNo " + saleNo);
                        Console.WriteLine("GetLatestSaleNo " + saleNo);
                    }

                    return(saleNo);
                    //return (4800);
                }
                catch (FTPCommandException fe)
                {
                    LogMsg(fe);
                    return(0);
                }
                catch (IOException ie)
                {
                    LogMsg(ie);
                    return(0);
                }
                catch (IndexOutOfRangeException ie)
                {
                    LogMsg(ie);
                    return(0);
                }
            }
        }
Exemple #32
0
        private static void DoSingleFileGet(FTPSClient client, string remotePathName)
        {
            string localPathName = null;
            string localDirName = null;
            if (commandArguments.Count > 1)
            {
                if (Directory.Exists(commandArguments[1]))
                    localDirName = commandArguments[1];
                else
                    localPathName = commandArguments[1];

            }
            else
                localDirName = Directory.GetCurrentDirectory();

            if (localPathName == null)
            {
                string remoteFileName = Path.GetFileName(remotePathName);
                localPathName = Path.Combine(localDirName, remoteFileName);
            }

            client.GetFile(remotePathName, localPathName, new FileTransferCallback(TransferCallback));
        }
Exemple #33
0
        private static void DoSys(FTPSClient client)
        {
            string systemInfo = client.GetSystem();

            Console.WriteLine("Remote system: \"" + systemInfo + "\"");
        }
Exemple #34
0
        private static void DoSingleFilePut(FTPSClient client, string localPathName)
        {
            string remotePathName = GetRemotePathName(localPathName);

            client.PutFile(localPathName, remotePathName, new FileTransferCallback(TransferCallback));
        }
Exemple #35
0
 private static void DoRenameFile(FTPSClient client)
 {
     client.RenameFile(NormalizeRemotePath(commandArguments[0]),
                       NormalizeRemotePath(commandArguments[1]));
 }
Exemple #36
0
 /// <summary>
 /// Initialises a new instance of the <see cref="FtpMessageSender"/> class.
 /// </summary>
 /// <param name="client">An object to communicate over FTP.</param>
 public FtpMessageSender(FTPSClient client)
 {
     this._ftpClient = client;
 }
Exemple #37
0
 private static void DoSingleFilePut(FTPSClient client, string localPathName)
 {
     string remotePathName = GetRemotePathName(localPathName);
     client.PutFile(localPathName, remotePathName, new FileTransferCallback(TransferCallback));
 }
Exemple #38
0
        public override IEnumerable <MessageInfo> GetMessageList()
        {
            var result = new List <MessageInfo>();

            Array.ForEach(telecom.GetList(TaskInfo["Path"]), (f) => { if (f.IsMatch(TaskInfo.Get("Name", "*")))
                                                                      {
                                                                          result.Add(new MessageInfo()
                    {
                        Name = f, CreationTime = telecom.GetFileDate(TaskInfo["Path"].IsEmpty() ? f : FTPSClient.GetPath(TaskInfo["Path"] + "/" + f))
                    });
                                                                      }
                          });
            return(result);
        }
Exemple #39
0
 private static void DoSys(FTPSClient client)
 {
     string systemInfo = client.GetSystem();
     Console.WriteLine("Remote system: \"" + systemInfo + "\"");
 }
Exemple #40
0
        private static void DoWildCardPut(FTPSClient client, string localPathPattern)
        {
            string localDirName = Path.GetDirectoryName(localPathPattern);
            string localFilePattern = Path.GetFileName(localPathPattern);

            filesTrasferredCount = 0;

            string remoteDirName = null;
            if (commandArguments.Count > 1)
                remoteDirName = NormalizeRemotePath(commandArguments[1]);

            client.PutFiles(localDirName, remoteDirName, localFilePattern, EPatternStyle.Wildcard, options.recursive, new FileTransferCallback(TransferCallback));

            Console.WriteLine();
            if (filesTrasferredCount > 0)
                Console.WriteLine("Uploaded files: {0}", filesTrasferredCount);
            else
                Console.Error.WriteLine("WARNING: No files uploaded");
        }
 public FTPServerFileSystem(FTPSClient handler)
 {
     _client = handler;
 }
Exemple #42
0
        public static string GetXMLFile(int saleid)
        {
            string   Host     = null;
            Int32    Port     = 0;
            string   Username = null;
            string   Password = null;
            string   thisone  = "";
            DateTime Latest   = Convert.ToDateTime("1/1/1970");

            // Get FTP credentials from config
//            Auction.AuctionConfig config = Administration.ReadConfigFile();

//            LogMsg("GetXMLFile");

            try
            {
                // Ftp Server settings

/*                                Host = config.FtpServer;
 *                              Username = config.FtpUser;
 *                              Password = Auction.DecodeFrom64(config.FtpPassword);
 *                              Port = Int32.Parse(config.FtpPort);*/
//                Host = "54.154.210.120";
                Host     = "192.168.44.40";
                Username = "******";
                Password = "******";
                Port     = 990;
            }
            catch (ArgumentNullException ne)
            {
                LogMsg(ne);
                return("");
            }
            catch (FormatException fe)
            {
                LogMsg(fe);
                return("");
            }

            string targetDirectory = "C:\\TransactionLogs";

            ulong?largest = 0;

            // Download the XML transcript and pop it into AMS...
            using (FTPSClient client = new FTPSClient())
            {
                try
                {
                    client.Connect(Host, Port,
                                   new NetworkCredential(Username,
                                                         Password),
                                   ESSLSupportMode.CredentialsRequired | ESSLSupportMode.DataChannelRequested | ESSLSupportMode.Implicit,
                                   new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications),
                                   new System.Security.Cryptography.X509Certificates.X509Certificate(),
                                   0, 0, 0, 60000, true);
                    LogMsg("GetXMLFile - FTP Connected to sale " + saleid);
                }
                catch (FTPCommandException fe)
                {
                    LogMsg(fe);
                    return("");
                }
                catch (IOException ie)
                {
                    LogMsg(ie);
                    return("");
                }
                catch (SocketException ie)
                {
                    LogMsg(ie);
                    return("");
                }

                try
                {
                    // Change to Transaction log directory
                    String pwd = client.GetCurrentDirectory();
                    client.SetCurrentDirectory("TransactionLogs");
                }
                catch (FTPCommandException fe)
                {
                    LogMsg(fe);
                    return("");
                }

                try
                {
                    string directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                                    @"Humboldt\AuctionController\transactionlogs\");
                    directory = "C:\\TransactionLogs\\";
                    // Make sure directory exists
                    if (Directory.Exists(directory))
                    {
                    }
                    else
                    {
                        Directory.CreateDirectory(directory);
                    }

                    {
                        // Find latest file
                        List <DirectoryListItem> ftpItems = client.GetDirectoryList().ToList();
                        LogMsg("GetXMLFile - Current Sale");

                        largest = 0;
                        foreach (DirectoryListItem FtpItem in ftpItems)
                        {
                            if (FtpItem.Name.IndexOf(saleid.ToString()) == 0)
                            {
                                ulong?size = client.GetFileTransferSize(FtpItem.Name);
                                if (size > largest)
                                {
                                    thisone = FtpItem.Name;
                                    largest = size;
                                }
                            }
                        }
                    }

                    LogMsg("GetXMLFile - getting " + thisone + " into " + directory + thisone);

                    if (thisone.Length > 0)
                    {
                        client.GetFile(thisone, directory + thisone);
                    }
                    return(directory + thisone);
                }
                catch (FTPCommandException fe)
                {
                    LogMsg(fe);
                    return("");
                }
                catch (IOException ie)
                {
                    LogMsg(ie);
                    return("");
                }
                catch (IndexOutOfRangeException ie)
                {
                    LogMsg(ie);
                    return("");
                }
            }
        }