/*************************************************************************** Windows Sockets Client Application Support Module Written by: John A. Junod Internet: 267 Hillwood Street Martinez, GA 30907 Compuserve: 72321,366 This program executable and all source code is released into the public domain. It would be nice (but is not required) to give me a little credit for any use of this code. THE INFORMATION AND CODE PROVIDED IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL JOHN A. JUNOD BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF JOHN A. JUNOD HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. *****************************************************************************/ #include "ws_glob.h" #include "ws_ftp.h" #include // access() #include // atoi() #include //strncmp char szInitDir[80]; char szSessionName[80]; #define MAXTYPES 18 LPSTR szHostTypes[MAXTYPES]={ "auto detect", "Chameleon", "FTP PC-TCP", "IBM-PC TCP/IP", "IBM-VM/MVS", "KA9Q/NOS", "NCSA/CUTCP", "SI NT FTPD", "Super TCP", "Unisys 5000 (EXOS)", "UNIX (default)", "VMS-Multinet", "VMS-UCX", "WinQVT/Net", "Windows NT", "Solaris - Unix", "Windows NT - Software Innovations", "OS2 PC Type L8" }; // int nTypes[MAXHOSTS]; BOOL bSavePWD=FALSE; BOOL bUseGateWay=FALSE; char szCrypt[160]; LPSTR szAnony="anonymous"; int nHostType=HOST_TYPE_AUTO; extern BOOL bHELP; extern BOOL bCanMKD,bCanRMD,bCanREN,bCanDELE; extern HBRUSH hbrGray1,hbrGray2; extern void check_scroll(); // lgk new function to get remote search string char *remotesearchstring() { unsigned char szBuf[120]; WORD cbText; *(WORD *) szBuf = sizeof(szBuf) -1; // sets the buffer size cbText = (WORD)SendMessage(hRdirBox, EM_GETLINE,(WPARAM)0,(DWORD)(LPSTR)szBuf); szBuf[cbText] = '\0'; return szBuf; } void LoadConfigNames(HWND); /* // this encryption is not secure nor is it intended to be // this is just to keep the password from being plain text // in the ini file. I'd really recommend people don't save // their passwords */ LPSTR EnCrypt(LPSTR userid,LPSTR passwd) { int nIndex; if(lstrcmp(userid,szAnony)==0) return(passwd); szCrypt[0]=0; for(nIndex=0;nIndex'9') return(c-'7'); return (c-'0'); } LPSTR DeCrypt(LPSTR userid,LPSTR passwd) { int nIndex; if(lstrcmp(userid,szAnony)==0) return(passwd); szCrypt[0]=0; for(nIndex=0;nIndex0) { WritePrivateProfileString(szSessionName,NULL,NULL,szIniFile); if((nIndex=SendDlgItemMessage(hWndDlg,DLG_HOST_NAME, CB_FINDSTRINGEXACT,0,(LONG)(LPSTR)szSessionName))!=CB_ERR) { SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,CB_DELETESTRING, nIndex,0l); } else nIndex=0; if(SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,CB_SETCURSEL,nIndex,0l) ==CB_ERR) SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,CB_SETCURSEL,0,0l); } GetDlgItemText(hWndDlg,DLG_HOST_NAME,szSessionName,79); SetDefaultHostStuff(hWndDlg,szSessionName); SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,WM_SETREDRAW,TRUE,0l); SetFocus(GetDlgItem(hWndDlg,DLG_HOST_NAME)); break; case DLG_BTN_SAVE: case IDOK: GetDlgItemText(hWndDlg,DLG_HOST_ADDRESS,szRemoteHost,79); if(GetDlgItemText(hWndDlg,DLG_HOST_NAME,szSessionName,79)==0) lstrcpy(szSessionName,szRemoteHost); GetDlgItemText(hWndDlg,DLG_HOST_USERID,szUserID,79); GetDlgItemText(hWndDlg,DLG_HOST_PASSWORD,szPassWord,79); GetDlgItemText(hWndDlg,DLG_HOST_DIR,szInitDir,79); uiRetries=GetDlgItemInt(hWndDlg,DLG_HOST_RETRIES,NULL,FALSE); uiFtpPort=GetDlgItemInt(hWndDlg,DLG_HOST_FTP_PORT,NULL,FALSE); nRC=GetDlgItemInt(hWndDlg,DLG_HOST_TIMEOUT,NULL,FALSE); if(nRC==0) uiTimeOut=65; else uiTimeOut=nRC; if(uiTimeOut > (65536/1000)) uiTimeOut=65530/1000; if(IsDlgButtonChecked(hWndDlg,DLG_HOST_PWD)) bSavePWD=TRUE; else bSavePWD=FALSE; nIndex=SendDlgItemMessage(hWndDlg,DLG_HOST_TYPE,CB_GETCURSEL,0,0l); if(nIndex==CB_ERR) nHostType=HOST_TYPE_AUTO; else nHostType=nIndex+HOST_TYPE_AUTO; SaveHostName(szSessionName); if (IsDlgButtonChecked(hWndDlg, DLG_HOST_GATEWAY)) { FARPROC lpfnMsgProc; use_gateway=1; lpfnMsgProc=MakeProcInstance((FARPROC)WS_GateMsgProc,hInst); nRC=DialogBox(hInst,(LPSTR)"DLG_GATEWAY",hWndDlg,lpfnMsgProc); FreeProcInstance(lpfnMsgProc); SetFocus(hWndDlg); } else use_gateway=0; if(LOWORD(wParam)==IDOK) EndDialog(hWndDlg, TRUE); else if(SendDlgItemMessage(hWndDlg,DLG_HOST_NAME, CB_FINDSTRINGEXACT,0,(LONG)(LPSTR)szSessionName)==CB_ERR) { SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,CB_ADDSTRING, 0,(LONG)(LPSTR)szSessionName); SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,WM_SETREDRAW,TRUE,0l); SetFocus(GetDlgItem(hWndDlg,DLG_HOST_NAME)); } break; case IDCANCEL: EndDialog(hWndDlg, FALSE); if(!bConnected) { EnableWindow(hBtnConnect,TRUE); EnableWindow(hBtnClose,FALSE); } break; } break; default: return FALSE; } return TRUE; } /*************************************************************** save the information about the current host in the ini file */ void SaveHostName(LPSTR lpszCName) { char buf[30]; WritePrivateProfileString(lpszCName,"HOST",szRemoteHost,szIniFile); WritePrivateProfileString(lpszCName,"UID",szUserID,szIniFile); if(bSavePWD) WritePrivateProfileString(lpszCName,"PWD", EnCrypt(szUserID,szPassWord),szIniFile); else WritePrivateProfileString(lpszCName,"PWD",NULL,szIniFile); if(szInitDir[0]!=0) WritePrivateProfileString(lpszCName,"DIR",szInitDir,szIniFile); else WritePrivateProfileString(lpszCName,"DIR",NULL,szIniFile); wsprintf(buf,"%u",nHostType); WritePrivateProfileString(lpszCName,"TYPE",buf,szIniFile); wsprintf(buf,"%u",uiTimeOut); WritePrivateProfileString(lpszCName,"TIMEOUT",buf,szIniFile); wsprintf(buf,"%u",uiRetries); WritePrivateProfileString(lpszCName,"RETRIES",buf,szIniFile); wsprintf(buf,"%u",uiFtpPort); WritePrivateProfileString(lpszCName,"FTPPORT",buf,szIniFile); } /***************************************************** convert remotename into something DOS can deal with here nt can deal with longer names */ // lgk add fix for vax which makes names with ;version numbe now MakeLocalName(LPSTR localname,LPSTR shortname, LPSTR remotename) { int nIndex; char Name[10],Ext[4],*s; char Name2[140], Ext2[80]; char savedname[256]; lstrcpy(savedname,remotename); // lgk on nt try the entire name first for localname while(*remotename!=0 && *remotename=='.') remotename++; for(nIndex=0;nIndex<140;nIndex++) if(*remotename!=0 && *remotename!='.' && *remotename!=' ') { if (nIndex < 8) Name[nIndex] = *remotename; Name2[nIndex] = *remotename++; } else break; if (nIndex <= 8) Name[nIndex]=0; else Name[8]=0; Name2[nIndex]=0; Ext2[0]=0; Ext[0] = 0; if((s=strchr(remotename,'.'))!=NULL) remotename=s; while(*remotename!=0 && (*remotename=='.' || *remotename==' ')) remotename++; if(*remotename!=0) { for(nIndex=0;nIndex<80;nIndex++) if(*remotename!=0 && *remotename!='.' && *remotename!=' ') { if (nIndex < 3) Ext[nIndex] = *remotename; Ext2[nIndex] = *remotename++; } else break; if (nIndex <=3) Ext[nIndex]=0; else Ext[3] = 0; Ext2[nIndex] = 0; } if(Ext[0]==0) { lstrcpy(shortname,Name); } else { wsprintf(shortname,"%s.%s",Name,Ext); } if(Ext2[0]==0) { lstrcpy(localname,Name2); } else { wsprintf(localname,"%s.%s",Name2,Ext); } if(lstrlen(shortname)==0) { lstrcpy(Name,"aaremote"); lstrcpy(shortname,Name); } if(lstrlen(localname)==0) { lstrcpy(Name,"aaremote"); lstrcpy(localname,Name2); } if(bRecvUniq) { nIndex=0; while((int)access(shortname,0)==0 && nIndex<99) { DoPrintf("[recvuniq] %s - %s - %s",Name,Ext,shortname); if(Ext[0]==0) wsprintf(shortname,"%s.%03u",Name,nIndex); else if(lstrlen(Name)>5) wsprintf(shortname,"%-5.5s%03u.%s",Name,nIndex,Ext); else wsprintf(shortname,"%s%03u.%s",Name,nIndex,Ext); nIndex++; } } if(bRecvUniq) { nIndex=0; while((int)access(localname,0)==0 && nIndex<99) { DoPrintf("[recvuniq] %s - %s - %s",Name2,Ext2,localname); if(Ext[0]==0) wsprintf(localname,"%s.%03u",Name2,nIndex); else if(lstrlen(Name)>5) wsprintf(localname,"%-5.5s%03u.%s",Name2,nIndex,Ext2); else wsprintf(localname,"%s%03u.%s",Name2,nIndex,Ext2); nIndex++; } } // on nt try whole name for local name lstrcpy(localname,savedname); // fix vax however { char *colonloc = strchr(savedname,';'); if (colonloc != 0) { int i = 0; while (savedname[i] != ';') { Name2[i] = savedname[i]; ++i; } Name2[i] = '\0'; lstrcpy(localname,Name2); } } return(TRUE); } /************************************************* find filename in a UNIX directory listing */ LPSTR FindName(LPSTR szLine) { int nIndex; char *pStr; // strip trailing garbage from the line if there is any. while((nIndex=strlen(szLine))>2 && (szLine[nIndex-1]==0x0a || szLine[nIndex-1]==0x0d || szLine[nIndex-1]==' ' || szLine[nIndex-1]==0x09)) szLine[nIndex]=0; // now the name SHOULD be the last thing on the line if((pStr=strrchr(szLine,' '))!=NULL || (pStr=strrchr(szLine,0x09))!=NULL) { while(*pStr && (*pStr==' ' || *pStr==0x09)) pStr++; return(pStr); } return(szLine); } /***************************************************************** This is the routine that take the output from LIST and breaks it down into files and directories. The format for the output from most of the machine types was provided by Chris Sacksteder. */ int GetRemoteDirForWnd(HWND hWnd) { char *pStr,*s,*t, *pStr2; FILE *fd; int result = 0; int nRC; char *searchstring = remotesearchstring(); int maxhfextent = 0; int maxhdextent = 0; char temp[120]; strcpy(temp,searchstring); // clean out the old contents of the list boxes SendMessage(hLbxRDir,LB_RESETCONTENT,0,0); SendMessage(hLbxRFiles,LB_RESETCONTENT,0,0); // lgk 7/94 new code for horiz scroll bars maxhfextent=0; maxhdextent=0; SendMessage(hLbxRFiles,LB_SETHORIZONTALEXTENT,0,0l); SendMessage(hLbxRDir,LB_SETHORIZONTALEXTENT,0,0l); // can't do much if we aren't connected if(!bConnected) { SendMessage(hTxtRDir,WM_SETTEXT,0,(LPARAM)""); } else { // get the remote directory name strcpy(szString,"undecipherable"); nRC=DoPWD(ctrl_socket); if(nRC==FTP_COMPLETE) { if((pStr=strchr(szMsgBuf,'"'))!=NULL) strncpy(szString,++pStr,180); if((pStr=strchr(szString,'"'))!=NULL) *pStr=0; else szString[180]=0; } SendMessage(hTxtRDir,WM_SETTEXT,0,(LPARAM)szString); if(!bHELP) ReadProcessHelp(ctrl_socket); // go get the current remote directory listing in tmpfile.tmp // lgk new code here to use search string if filled in if (strlen(temp) != 0) { char temp2[200]; strcpy(temp2,"LIST "); strcat(temp2,temp); nRC=DoDirList(ctrl_socket,temp2); } else nRC=DoDirList(ctrl_socket,"LIST"); SendMessage(hLbxRDir,LB_ADDSTRING,0,(LPARAM)".."); if(nRC==FTP_COMPLETE) { if((fd=fopen(szTmpFile,"r"))!=NULL) { while(fgets(szString,180,fd)!=NULL) { if((pStr=strchr(szString,'\n'))!=NULL) *pStr=0; switch(nHostType) { case HOST_TYPE_SUPER: case HOST_TYPE_CHAMELEON: case HOST_TYPE_NCSA: // looks like a standard DOS directory // filename.ext (or size) date,etc... if(strstr(szString,"")!=NULL || strstr(szString,"")!=NULL) { if((pStr=strchr(szString,' '))!=NULL) *pStr=0; if(strcmp(szString,".")!=0 && strcmp(szString,"..")!=0) { SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString); // lgk 7/94 new code for horiz scroll bars check_scroll(hLbxRDir,(LONG)szString,&maxhdextent); } } else { if((pStr=strchr(szString,' '))!=NULL) *pStr=0; if(szString[0]!=0) SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString); // lgk 7/94 new code for horiz scroll bars check_scroll(hLbxRFiles,(LONG)szString,&maxhfextent); } break; // lgk new code for software innovations server case HOST_TYPE_INNOV_WINDOWS_NT: if(strncmp(szString,"d ",5)== 0) { pStr = strstr(szString,"d "); // ok it is a dir now skip over to the name field always starting at column 51 pStr = pStr + 51; SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr); check_scroll(hLbxRDir,(LONG)pStr,&maxhdextent); } else { pStr = strstr(szString," "); /* get to the name */ pStr = pStr + 51; /* Now we have the name */ SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr); check_scroll(hLbxRFiles,(LONG)pStr,&maxhfextent); } break; // lgk new code for OS2 pc Type L8 ftpd /* The volume label in drive C is OS2. The Volume Serial Number is 2574:C014 Directory of C:\IBETA . 11-28-94 10:47a .. 11-28-94 10:47a IMAIL ZIP 246582 11-28-94 10:49a ISMTPD32 EXE 79360 11-21-94 3:27p IPOP3D32 EXE 70144 11-21-94 3:26p ISMTPD32 TXT 1310 11-29-94 6:51p 6 File(s) 8583168 bytes free */ case HOST_TYPE_OS2_L8: // looks like a standard DOS directory except space before extension // filename ext (or size) date,etc... if(strstr(szString,"")!=NULL || strstr(szString,"")!=NULL) { if((pStr=strchr(szString,' '))!=NULL) *pStr=0; if(strcmp(szString,".")!=0 && strcmp(szString,"..")!=0) { SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString); // lgk 7/94 new code for horiz scroll bars check_scroll(hLbxRDir,(LONG)szString,&maxhdextent); } } else { // name is first 8 up till space and then skip 1 and next 3 if not all blank if((pStr=strchr(szString,' '))!=NULL) *pStr=0; if(szString[0]!=0) { char lhsname[9]; char extens[4]; char finalstring[13]; BOOLEAN hasext = FALSE; int i = 0; int lastpos = 0; // DoPrintf("string is %s ",szString); // find name lenght for (i=0; i<=7; i++) if (szString[i] != ' ') { lhsname[i] = szString[i]; lastpos = i + 1; } lhsname[lastpos] = '\0'; for (i=9; i<=11; i++) { if (szString[i] != ' ') { extens[i-9] = szString[i]; hasext = TRUE; } else extens[i-9] = '\0'; } strcpy(finalstring,lhsname); // DoPrintf("fname = %s ",lhsname); // DoPrintf("extension = %s",extens); // DoPrintf("finalstring = %s",finalstring); if (hasext == TRUE) { strcat(finalstring,"."); strcat(finalstring,extens); // DoPrintf("new finalstring = %s",finalstring); } // else SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString); SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)finalstring); // lgk 7/94 new code for horiz scroll bars check_scroll(hLbxRFiles,(LONG)szString,&maxhfextent); } } break; case HOST_TYPE_WINDOWS_NT: // lgk extra code here to check if we have an nt server but in unix mode then reset type to unix // we know this if the directory comes back with a - in col 9 as it will be a space in the dos format mode if (szString[8] == '-') // we have a unix mode { DoPrintf("NOTE: NT Server is in Unix Mode ... Resetting host type."); nHostType = HOST_TYPE_UNIX; pStr=FindName(szString); // if line starts with 'd' its a directory if(strchr("dl",szString[0])!=NULL) { if(pStr[strlen(pStr)-1]=='/' || // 93.12.04 fix for some NT ftpd pStr[strlen(pStr)-1]=='\\') // 93.12.04 pStr[strlen(pStr)-1]=0; // 93.12.04 if(strcmp(pStr,".")!=0 && strcmp(pStr,"..")!=0) { SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr); check_scroll(hLbxRDir,(LONG)pStr,&maxhdextent); } } else // if line starts with - or f its a file if(nHostType==HOST_TYPE_SINTFTPD || strchr("-f",szString[0])!=NULL) { // lgk fix bug here that checked length with szstring when name is pstr at this point SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr); check_scroll(hLbxRFiles,(LONG)pStr,&maxhfextent); } } else // not unix format note: this code should only be hit once as the type changes to unix { if (strstr(szString,"")!=NULL) { pStr = strstr(szString,""); if ((pStr = strrchr(pStr,' ')) != NULL) { /* now we should be on name so get it */ ++pStr; if(strcmp(pStr,".")!=0 && strcmp(pStr,"..")!=0) { SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr); check_scroll(hLbxRDir,(LONG)pStr,&maxhdextent); } } } else { /* get to the name */ if ((pStr = strrchr(szString,' ')) != NULL) { ++pStr; /* Now we have the name */ SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr); check_scroll(hLbxRFiles,(LONG)pStr,&maxhfextent); } } } break; case HOST_TYPE_QVT: // if the name is the first thing on the line and ends with a slash // to indicate a directory if((s=strchr(szString,' '))!=NULL) *s=0; // use for ftp.uwp.edu if(szString[strlen(szString)-1]=='/' || szString[strlen(szString)-1]=='\\') { szString[strlen(szString)-1]=0; if(strcmp(szString,".")!=0 && strcmp(szString,"..")!=0) { SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString); check_scroll(hLbxRDir,(LONG)szString,&maxhdextent); } } else { SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString); check_scroll(hLbxRFiles,(LONG)szString,&maxhfextent); } break; case HOST_TYPE_IBM_VM: // IBM VM/VMS listing // filename extent (what does a directory look like??) szString[18]=0; while(strlen(szString)>1 && szString[strlen(szString)-1]==' ') szString[strlen(szString)-1]=0; if((s=strchr(szString,' '))!=NULL) { *s++ = '.'; t=s; while(*t && *t==' ') t++; if(*t && t!=s) strcpy(s,t); } if(*s && *s!=' ' && *s!='\t') // 93.12.04 eliminate blank lines { SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString); check_scroll(hLbxRFiles,(LONG)szString,&maxhfextent); } break; case HOST_TYPE_VMS_UCX: case HOST_TYPE_VMS_MULTINET: // DEC listing if(*szString!=' ') { if((s=strchr(szString,';'))!=NULL) { *s=0; if(strlen(szString)>4 && strcmp(&szString[strlen(szString)-4],".DIR")==0) { szString[strlen(szString)-4]=0; SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString); check_scroll(hLbxRDir,(LONG)szString,&maxhdextent); } else { *s=';'; if((s=strchr(szString,' '))!=NULL) *s=0; if((s=strchr(szString,'\t'))!=NULL) *s=0; SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString); check_scroll(hLbxRFiles,(LONG)szString,&maxhfextent); } } } break; case HOST_TYPE_PCTCP: // size..... filename.ext ....... // filename.ext ....... szString[30]=0; s=FindName(szString); if(strnicmp(szString,"",5)==0) { if(strcmp(s,".")!=0 && strcmp(s,"..")!=0) { SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)s); check_scroll(hLbxRDir,(LONG)s,&maxhdextent); } } else { SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)s); // lgk fix bug here that checked length with szstring when name is s at this point check_scroll(hLbxRFiles,(LONG)s,&maxhfextent); } break; case HOST_TYPE_IBM_TCP: // ........ filename.ext // ........ DIR filename.ext - host ibm tcp // ........ size filename.ext s=FindName(szString); if(strstr(szString," DIR ")!=NULL || strstr(szString,"")!=NULL) { if(strcmp(s,".")!=0 && strcmp(s,"..")!=0) { SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)s); check_scroll(hLbxRDir,(LONG)s,&maxhdextent); } } else { SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)s); // lgk fix bug here that checked length with szstring when name is s at this point check_scroll(hLbxRFiles,(LONG)s,&maxhfextent); } break; case HOST_TYPE_NOS: // ka9q if(strstr(szString,"Disk size")==NULL) { szString[13]=0; nRC=13; while((nRC=strlen(szString))>0 && szString[nRC-1]==' ') szString[nRC-1]=0; if(*szString!=0) { if(szString[strlen(szString)-1]=='/' || szString[strlen(szString)-1]=='\\') { szString[strlen(szString)-1]=0; if(strcmp(szString,".")!=0) { SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)szString); check_scroll(hLbxRDir,(LONG)szString,&maxhdextent); } } else { SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)szString); check_scroll(hLbxRFiles,(LONG)szString,&maxhfextent); } } pStr=&szString[41]; nRC=13; pStr[nRC]=0; while((nRC=strlen(pStr))>0 && pStr[nRC-1]==' ') pStr[nRC-1]=0; if(*pStr!=0) { if(pStr[strlen(pStr)-1]=='/' || pStr[strlen(pStr)-1]=='\\') { pStr[strlen(pStr)-1]=0; if(strcmp(pStr,".")!=0 && strcmp(pStr,"..")!=0) { SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr); check_scroll(hLbxRDir,(LONG)pStr,&maxhdextent); } } else { SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr); // lgk fix bug here that checked length with szstring when name is pstr at this point check_scroll(hLbxRFiles,(LONG)pStr,&maxhfextent); } } } break; case HOST_TYPE_SINTFTPD: case HOST_TYPE_U5000: case HOST_TYPE_UNIX: case HOST_TYPE_SOLARIS: default: // assume UNIX ls format pStr=FindName(szString); // if line starts with 'd' its a directory if(strchr("dl",szString[0])!=NULL) { if(pStr[strlen(pStr)-1]=='/' || // 93.12.04 fix for some NT ftpd pStr[strlen(pStr)-1]=='\\') // 93.12.04 pStr[strlen(pStr)-1]=0; // 93.12.04 // lgk for now for links we put the final directory in the window.... however // for cases where we have a ./ something or ../something we don't put anything // so fix this and put instead of the final directory the link name // the question is here for links do we want to display the final name // complete with .. or do we want to display the link name // to be consistent I'll display the // link name because that is what the new versions of ws ftp do if (szString[0] == 'l') { // find " ->" pStr2=strstr(szString," ->"); if (pStr2 != NULL) { pStr2[0] = 0; // find new name now that we have removed the -> pStr=FindName(szString); // DoPrintf("adding %s ",pStr); SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr); check_scroll(hLbxRDir,(LONG)pStr,&maxhdextent); } } else if(strcmp(pStr,".")!=0 && strcmp(pStr,"..")!=0) { SendMessage(hLbxRDir,LB_ADDSTRING,0,(LONG)pStr); check_scroll(hLbxRDir,(LONG)pStr,&maxhdextent); } } else // if line starts with - or f its a file if(nHostType==HOST_TYPE_SINTFTPD || strchr("-f",szString[0])!=NULL) { // lgk fix bug here that checked length with szstring when name is pstr at this point SendMessage(hLbxRFiles,LB_ADDSTRING,0,(LONG)pStr); check_scroll(hLbxRFiles,(LONG)pStr,&maxhfextent); } break; } } fclose(fd); } else DoAddLine("couldn't open tmpfile for read."); } else DoPrintf("DoDirList returned %u",nRC); } // if we were connected SendMessage(hRdirBox,EM_SETMODIFY,0,0); return 0; } /* Read the output from HELP and see if we can determine the hosttype (if we don't already know it) and determine what functions are valid (things like mkdir, etc) lgk bug fix for solaris where remotehelp hangs the system. */ int ReadProcessHelp(SOCKET ctrl_socket) { int iRetCode; // lgk add support for getting the other types by executing the syst command BOOL defaulttype = FALSE; bCanMKD=bCanRMD=bCanREN=bCanDELE=FALSE; // lgk don't send help for solaris if (nHostType != HOST_TYPE_SOLARIS) { if(SendPacket(ctrl_socket,"HELP")!=-1) { iRetCode=ReadLine(ctrl_socket); if((iRetCode/100)==5 && nHostType==HOST_TYPE_AUTO) nHostType=HOST_TYPE_NOS; else { if(nHostType==HOST_TYPE_AUTO) { if(strstr(szMsgBuf,"NCSA")!=NULL || strstr(szMsgBuf,"CUTCP")!=NULL) nHostType=HOST_TYPE_NCSA; else if(strncmp(szMsgBuf,"214-PC FTP server",17)==0 || strstr(szMsgBuf,"QVT")!=NULL) nHostType=HOST_TYPE_QVT; else { defaulttype = TRUE; nHostType=HOST_TYPE_UNIX; } } while((iRetCode!=421) && ((iRetCode/100)!=2 || szMsgBuf[3]=='-')) { if(strstr(szMsgBuf,"MKD")!=NULL) bCanMKD=TRUE; if(strstr(szMsgBuf,"RMD")!=NULL) bCanRMD=TRUE; if(strstr(szMsgBuf,"RNFR")!=NULL) bCanREN=TRUE; if(strstr(szMsgBuf,"DELE")!=NULL) bCanDELE=TRUE; iRetCode=ReadLine(ctrl_socket); } } // if the host type defaulted to unix then try syst instead if (defaulttype) { if(SendPacket(ctrl_socket,"SYST")!=-1) { DoPrintf("%s","SYST"); iRetCode=ReadLine(ctrl_socket); DoPrintf("%s",szMsgBuf); if(strstr(szMsgBuf,"Windows_NT")!=NULL) nHostType=HOST_TYPE_WINDOWS_NT; else if(strstr(szMsgBuf,"WINDOWS NT Type: L8")!=NULL) nHostType=HOST_TYPE_INNOV_WINDOWS_NT; else if(strstr(szMsgBuf,"UNIX") !=NULL) nHostType=HOST_TYPE_UNIX; else if(strstr(szMsgBuf,"MultiNet") !=NULL) nHostType=HOST_TYPE_VMS_MULTINET; else if(strstr(szMsgBuf,"MultiNet") !=NULL) nHostType=HOST_TYPE_VMS_MULTINET; else if(strstr(szMsgBuf,"VMS") !=NULL) nHostType=HOST_TYPE_VMS_UCX; else if(strstr(szMsgBuf,"PC Type: L8") !=NULL) nHostType=HOST_TYPE_OS2_L8; // add others later as we find out the type } } } } else // host type is solaris so hardcode stuff { bCanMKD=TRUE; bCanRMD=TRUE; bCanREN=TRUE; bCanDELE=TRUE; iRetCode=214; } EnableWindow(hBtnRMKD,bCanMKD); EnableWindow(hBtnRRMD,bCanRMD); EnableWindow(hBtnRREN,bCanREN); EnableWindow(hBtnRDEL,bCanDELE); bHELP=TRUE; DoPrintf("Host type (%u): %s",nHostType-6000,szHostTypes[nHostType-6000]); return iRetCode; } //*************************************************// // routines to load and save our list of hostnames // //*************************************************// LPSTR cfgname ="_config_"; int GPPS(LPSTR fldname,LPSTR deflt,LPSTR destination,int len) { return(GetPrivateProfileString(cfgname,fldname, deflt,destination,len,szIniFile)); } int WPPS(LPSTR fldname,LPSTR value) { return (WritePrivateProfileString(cfgname,fldname,value,szIniFile)); } void LoadConfigNames(HWND hWndDlg) { FILE *fp; char szPathName[156]; char *s; szPathName[0]=0; if(GetWindowsDirectory(szPathName,144)!=0) lstrcat(szPathName,"\\"); lstrcat(szPathName,szIniFile); if((fp=fopen(szPathName,"r"))!=NULL) { while(fgets(szPathName,150,fp)!=NULL) if(szPathName[0]=='[') { if((s=strchr(szPathName,']'))!=NULL) *s=0; if(stricmp(&szPathName[1],cfgname)!=0) SendDlgItemMessage(hWndDlg,DLG_HOST_NAME,CB_ADDSTRING,0, (LONG)(LPSTR)&szPathName[1]); } fclose(fp); } } void LoadUserInfo() { UINT flags; // int nIndex; // LPSTR s; szSessionName[0]=0; szMailAddress[0]=0; szViewer[0]=0; szUserID[0]=0; szPassWord[0]=0; szInitDir[0]=0; nHostType=HOST_TYPE_AUTO; uiTimeOut=65; uiRetries=0; uiFtpPort=21; GPPS("SESSION", NULL, szSessionName, 79); GPPS("MAILADDR",NULL, szMailAddress,127); GPPS("VIEWER", "notepad", szViewer, 120); bAutoStart=GetPrivateProfileInt(cfgname, "AUTOSTART", bAutoStart,szIniFile); flags=GetPrivateProfileInt(cfgname,"FLAGS",64+4+1,szIniFile); if(flags & 1) bRecvUniq=1; else bRecvUniq=0; if(flags & 2) bStorUniq=1; else bStorUniq=2; if(flags & 4) bBell=1; else bBell=0; if(flags & 8) bInteractive=1; else bInteractive=0; if(flags & 16) bVerbose=1; else bVerbose=0; if(flags & 32) bHash=1; else bHash=2; //if(flags & 64) bSendPort=1; else bSendPort=0; if(flags & 128) bDoGlob=1; else bDoGlob=2; } void SaveUserInfo() { UINT flags; // int nIndex; WPPS(NULL, NULL); WPPS("SESSION", szSessionName); WPPS("MAILADDR", szMailAddress); WPPS("VIEWER", szViewer); wsprintf(szString,"%u",bAutoStart); WPPS("AUTOSTART",szString); flags=((bRecvUniq==1)?1:0) + // ((bStorUniq==1)?2:0) + ((bBell==1)?4:0) + ((bInteractive==1)?8:0)+ // ((bHash==1)?32:0) + // ((bSendPort==1)?64:0) + // ((bDoGlob==1)?128:0) + ((bVerbose==1)?16:0); wsprintf(szString,"%u",flags); WPPS("FLAGS",szString); }