示例#1
0
        static void Main(string[] args)
        {
            string[] args01 = {"-targetLocation", @"c:\test", "-sourceFolder", @"c:\tester\tester"};
            string[] args02 = {"-targetLocationd"};
            string[] args03 = {"--help"};
            string[] args04 = {"-targetLocation", @"c:\test", "-sourceFolder"};
            string[] args05 = {"-targetLocation", @"c:\test", "-sourceFolder", "value"};
            string[] args06 = {"-targetLocation", @"c:\test", "-sourceFolder", @"c:\tester\tester", "--debug", "true"};
            string[] args07 = {"/?"};
            string[] args08 = {"-?"};

            //args = args06;

            CommandLineArgs.CmdLine cl = new CommandLineArgs.CmdLine( isConsole : true );

            cl.AddHelpLine("Test CmdLine class.");
            cl.AddHelpLine("More information here.");

            cl.AddRequiredArgumentDefinition("-targetLocation", "Fully qualified folder name of target location.");
            cl.AddOptionalArgumentDefinition("-sourceFolder", "Fully qualified folder name of source location.");

            cl.Initialize(args);

            var argValue = cl.GetArgumentValue("-targetLocation");
            if (!String.IsNullOrEmpty(argValue)) {
                Console.WriteLine(argValue);
            }

            argValue = cl.GetArgumentValue("-sourceFolder");
            if (!String.IsNullOrEmpty(argValue)) {
                Console.WriteLine(argValue);
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
示例#2
0
文件: Program.cs 项目: rogerpence/FTP
        static void Main(string[] args)
        {
            //Environment.SetEnvironmentVariable( "working-folder", @"C:\rpDocuments\Programs\MR\ParadePrototype\FrankieLee" );
            string workingFolder = Environment.GetEnvironmentVariable( "workingfolder", EnvironmentVariableTarget.Process );

            CommandLineArgs.CmdLine cl = new CommandLineArgs.CmdLine();

            //args = new string[] { "-method", "download", "-pcfilename", @"C:\rpDocuments\Programs\MR\ParadePrototype\FrankieLee\testone.rpg", "-member", "hellorpg" };
            //args = new string[] { "-method", "download", "-pcfilename", "roger.rpg", "-member", "hellorpg" };
            //args = new string[] { "--help" };

            cl.AddHelpLine("FTP source member upload or download.");
            cl.AddHelpLine("Set enviroment variable 'workingfolder' so you");
            cl.AddHelpLine("can use just the filename portion of pcFilename.");

            cl.AddRequiredArgumentDefinition("-method", "get(upload) or put(download).");
            cl.AddRequiredArgumentDefinition("-pcFilename", "Fully qualified PC file name.");
            cl.AddRequiredArgumentDefinition("-member", "IBM i member name.");
            cl.AddOptionalArgumentDefinition("-server", "Server name or IP address.");
            cl.AddOptionalArgumentDefinition("-library", "IBM i library name.");
            cl.AddOptionalArgumentDefinition("-sourceFile", "IBM i source physical file.");
            cl.AddOptionalArgumentDefinition("-user", "IBM i user name.");
            cl.AddOptionalArgumentDefinition("-password", "IBM i user password.");

            cl.Initialize(args);

            string pcFilename = cl.GetArgumentValue("-pcFileName");

            if (!String.IsNullOrEmpty(workingFolder)) {
                workingFolder = (workingFolder.EndsWith(@"\")) ? workingFolder : workingFolder + @"\";
                pcFilename = workingFolder + pcFilename;
            }

            Ftp ftp = new Ftp() {server = cl.GetArgumentValue("-server", "Cypress"),
                                 library = cl.GetArgumentValue("-library", "rpmobile"),
                                 sourceFile = cl.GetArgumentValue("-sourceFile", "qrpglesrc"),
                                 user = cl.GetArgumentValue("-user", "rogerso"),
                                 password = cl.GetArgumentValue("-password", "ASNA")};

            string result = "";
            string member = cl.GetArgumentValue( "-member" );

            try {
                if (cl.GetArgumentValue("-method").ToLower() == "put" || cl.GetArgumentValue("-method").ToLower() == "upload" )  {
                    result = ftp.Put( pcFilename, member );
                    Console.WriteLine("Uploaded {0}\r\n to {1}/{2}/{3}/{4}.", pcFilename, ftp.server, ftp.library, ftp.sourceFile, member);
                }
                else if ( cl.GetArgumentValue( "-method" ).ToLower() == "get" || cl.GetArgumentValue( "-method" ).ToLower() == "download") {
                    result = ftp.Get( pcFilename, member );
                    Console.WriteLine( "Downloaded {0}\r\n from {1}/{2}/{3}/{4}.", pcFilename, ftp.server, ftp.library, ftp.sourceFile, member );
                }
                else {
                    throw new Exception( "-method must be be 'get', 'download',  'put', or 'upload'." );
                }
            }
            catch ( System.Exception e ) {
                Console.WriteLine("*ERROR* Program failure...");
                Console.WriteLine(e.Message);
                Console.WriteLine("Note: 'error (426)' probably means the IBM member doesn't exist.");
            }

            Console.WriteLine(result);
            //Console.WriteLine("Press any key to continue...");
            //Console.ReadKey();
        }