ftpwrapper.cxx

Go to the documentation of this file.
00001 //
00002 // Copyright 2002, Lowell Boggs Jr.
00003 //
00004 // This file or directory, containing source code for a computer program,
00005 // is Copyrighted by Lowell Boggs, Jr.  987 Regency Drive, Lewisville
00006 // TX (USA), 75067.  You may use, copy, modify, and distribute this
00007 // source file without charge or obligation so long as you agree to
00008 // the following:
00009 //
00010 //  1.  You must indemnify Lowell Boggs against any and all financial
00011 //      obligations caused by its use, misuse, function, or malfunction.
00012 //      Further, you acknowledge that there is no warranty of any kind,
00013 //      whatsoever.
00014 //
00015 //  2.  You agree not to attempt to patent any portion of this original
00016 //      work -- though you may attempt to patent your own extensions to
00017 //      it if you so choose.
00018 //
00019 //  3.  You keep this copyright notice with the file and all copies
00020 //      of the file and do not change it anyway except language translation.
00021 //
00022 // You are responsible for enforcing your own compliance with these
00023 // conditions and may not use this source file if you cannot agree to the
00024 // above terms and conditions.
00025 
00026 //@File
00027 //
00031 
00032 
00033 #include <cxxtls/ftp.h>
00034 #include <cxxtls/options.h>
00035 #include <stdlib.h>
00036 
00037 using namespace std;
00038 using namespace cxxtls;
00039 
00040 int main(int argc, char **argv, char **environ)
00041 {
00042   ProgramOptions op("-stat,-get,-put,-del", argc, argv, environ);
00043 
00044   int status = 0;
00045   int get    = 0;
00046   int put    = 0;
00047   int del    = 0;
00048 
00049   if(op.option("-stat"))
00050     status = 1;
00051 
00052   if(op.option("-get"))
00053     get = 1;
00054 
00055   if(op.option("-put"))
00056     put = 1;
00057 
00058   if(op.option("-del"))
00059     del = 1;
00060 
00061   if( (get + del + put + status) > 1 )
00062   {
00063     cerr << "only one of -get, -put, -del, or -stat can be issued at a time" << endl;
00064     exit(1);
00065   }
00066 
00067 
00068   if(   (    (!get && !put) 
00069           && (op.argv.size() != 5) 
00070         ) 
00071      || (   ( (get  ||  put) 
00072               && (op.argv.size() < 5)
00073             )
00074          || (op.argv.size() > 6) 
00075         )
00076     )
00077   {
00078     cerr << "Error:  expected exactly 4 non-option parameters" << endl
00079          << "        hostname" << endl
00080          << "        username" << endl
00081          << "        password" << endl
00082          << "        file search pattern" << endl
00083          << ((get || put ) ? "        [localfile]" : "" ) << endl
00084          ;
00085         
00086     cerr << "        Options are " << endl
00087          << "          -stat  -- display file status as well as the names " << endl
00088          << "          -get   -- fetch a remote file " << endl
00089          << "          -put   -- copy a local file to the remote system " << endl
00090          << "          -del   -- delete a file on the remote system " << endl;
00091         
00092     exit(1);
00093 
00094   }
00095 
00096   if(status)
00097   {
00098     list<FTP::FileInfo> lf;
00099 
00100     int count = FTP::stat_matching(op.argv[1],
00101                                    op.argv[2],
00102                                    op.argv[3],
00103                                    op.argv[4],
00104                                    &lf
00105                                   );
00106                                 
00107    if(count >= 0)
00108    {
00109      list<FTP::FileInfo>::const_iterator i = lf.begin();
00110 
00111      while( i != lf.end() )
00112      {
00113        cout << i->status_ << " " << i->name_ << endl;
00114        ++i;
00115      }
00116 
00117      cout << count << " matches found" << endl;
00118    }
00119    else
00120    {
00121      cout << FTP::error() << endl;
00122    }
00123   }
00124   else
00125   if(get)
00126   {
00127     string tmp;
00128 
00129     if(op.argv.size() == 6)
00130       tmp = op.argv[5];
00131 
00132     if(FTP::get(op.argv[1],op.argv[2],op.argv[3],op.argv[4], tmp))
00133     {
00134       cerr << FTP::error() << endl;
00135     }
00136   }
00137   else
00138   if(del)
00139   {
00140     if(FTP::del(op.argv[1],op.argv[2],op.argv[3],op.argv[4]))
00141     {
00142       cerr << FTP::error() << endl;
00143     }
00144   }
00145   else
00146   if(put)
00147   {
00148     string tmp;
00149 
00150     if(op.argv.size() == 6)
00151       tmp = op.argv[5];
00152 
00153     if(FTP::put(op.argv[1],op.argv[2],op.argv[3],op.argv[4], tmp))
00154     {
00155       cerr << FTP::error() << endl;
00156     }
00157   }
00158   else
00159   {
00160     list<FTP::FileInfo> lf;
00161 
00162     int count = FTP::stat_matching(op.argv[1],
00163                                    op.argv[2],
00164                                    op.argv[3],
00165                                    op.argv[4],
00166                                    &lf
00167                                   );
00168                                 
00169    if(count >= 0)
00170    {
00171      list<FTP::FileInfo>::const_iterator i = lf.begin();
00172 
00173      while( i != lf.end() )
00174      {
00175        cout << i->name_ << endl;
00176        ++i;
00177      }
00178 
00179      cout << count << " matches found" << endl;
00180 
00181    }
00182    else
00183    {
00184      cout << FTP::error() << endl;
00185    }
00186   }
00187 
00188   exit(0);
00189 
00190 }
Generated on Wed Feb 29 22:50:03 2012 for CXXUtilities by  doxygen 1.6.3