home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / wsftp2.zip / LOGIN.C < prev    next >
C/C++ Source or Header  |  1994-06-03  |  3KB  |  126 lines

  1. // larry kahn addition to ws_ftp32 to support the default
  2. // ws_ftp32 host:directory/file format to automaticall logon and retrieve the
  3. // file
  4.  
  5. //----------------------
  6. #include "ws_glob.h"
  7. #include "WS_ftp.H"
  8. #include "version.h"
  9. #include <process.h>
  10.  
  11. extern void set_busy(BOOLEAN);
  12.  
  13.   char hostname[150];
  14.   char pathname[256];
  15.          
  16. void login_retrieve(remotename)
  17.  char *remotename;
  18.  
  19. {
  20.   char shortname[80];
  21.   char tmp[80];
  22.   char localname[220];
  23.   int nRC = 0;
  24.   char *lastslash;
  25.   char rname2[220];
  26.  
  27.   // lgk before calling makelocalname we need to strip only the name
  28.   // off of the remotepath/name so keep looking for / until we don't find
  29.   // one
  30.  
  31.   lastslash = strrchr(remotename,'/');
  32.   strcpy(rname2,lastslash+1);
  33.   MakeLocalName(localname,shortname,rname2);
  34.   DoPrintf("receiving %s as %s",remotename,localname);
  35.   wsprintf(tmp,"RETR %s",remotename);
  36.   nRC=RetrieveFile((SOCKET)ctrl_socket,(LPSTR)tmp,
  37.                      (LPSTR)localname,(LPSTR)shortname,fType);
  38.   if(nRC==2)
  39.     SendMessage(hLbxLFiles,LB_ADDSTRING,0,(LONG)remotename);
  40.               
  41.  // GetLocalDirForWnd(hWnd);
  42. }
  43.  
  44.  
  45. DWORD login_connect()
  46.  
  47. {
  48.    strcpy(szRemoteHost,hostname);
  49.  
  50.    DoPrintf("sz remote hostname = %s \n",szRemoteHost);
  51.  
  52.    use_gateway = 0;
  53.    lstrcpy(szUserID,"anonymous");
  54.    lstrcpy(szPassWord,szMailAddress);
  55.    
  56.    ctrl_socket=(SOCKET)DoConnect(szRemoteHost);
  57.      if(ctrl_socket!=INVALID_SOCKET)
  58.       {
  59.             // no need to change directory got connected just get file
  60.             login_retrieve(pathname);
  61.       }
  62. set_busy(FALSE);
  63. // only exit if download suceeded
  64. if (globalsucceed == TRUE)
  65.   {
  66.     exit(0);
  67.   }
  68. return 0;
  69. }
  70.  
  71. int check_command_line()
  72.  
  73. {
  74.  
  75.  // char filename[256];
  76.   LPSTR commandline = NULL;
  77.   char *sptr = NULL;
  78.   char *colon = NULL;
  79.   
  80.   commandline = GetCommandLine();
  81.  
  82.   if (commandline == NULL)
  83.      DoPrintf("Error getting command line\n");
  84.  
  85.   // see if we have :
  86.  else
  87.  {
  88.  
  89.   // lgk need to find colon after first space so we don't find colons
  90.   // in the executable name
  91.  
  92.    {
  93.   // now that we have the command line skip over to the execut. name
  94.   sptr = strstr(commandline," ");
  95.   if (sptr == NULL)
  96.     {
  97.      return 0;
  98.     }
  99.     
  100.  else
  101.    {
  102.  
  103.     colon = strstr(sptr,":");
  104.     if (colon == NULL)
  105.       {
  106.        return 0;
  107.       }
  108.   
  109.   else
  110.           {
  111.             /* ok we have a colon now pull of the host name */
  112.             strncpy(hostname,sptr+1,colon-(sptr+1));
  113.             /* now get the file name */
  114.             strcpy(pathname,(LPSTR)colon+1);
  115.  
  116.            // print out for debugging
  117.  //          DoPrintf("Host name is %s path name is %s \n",hostname,pathname);
  118.             set_busy(TRUE);
  119.              threadhandle = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)login_connect,NULL,0,&threadid);
  120.            return 1;
  121.           } 
  122.     }
  123.    }
  124.   }
  125. }
  126.