Esempio n. 1
0
        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();
        }