home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / vxftpsrc.zip / REMOTE.VRX < prev    next >
Text File  |  1995-10-07  |  49KB  |  1,557 lines

  1. /*:VRX         Main
  2. */
  3. /*  Main
  4. */
  5. Main:
  6. /*  Process the arguments.
  7.     Get the parent window.
  8. */
  9.     parse source . calledAs .
  10.     parent = ""
  11.     argCount = arg()
  12.     argOff = 0
  13.     if( calledAs \= "COMMAND" )then do
  14.         if argCount >= 1 then do
  15.             parent = arg(1)
  16.             argCount = argCount - 1
  17.             argOff = 1
  18.         end
  19.     end
  20.     InitArgs.0 = argCount
  21.     if( argCount > 0 )then do i = 1 to argCount
  22.         InitArgs.i = arg( i + argOff )
  23.     end
  24.     drop calledAs argCount argOff
  25.  
  26. /*  Load the windows
  27. */
  28.     call VRInit
  29.  
  30. /*
  31.     parse source . . spec
  32.     _VREPrimaryWindowPath = ,
  33.         VRParseFileName( spec, "dpn" ) || ".VRW"
  34.     _VREPrimaryWindow = ,
  35.         VRLoad( parent, _VREPrimaryWindowPath )
  36.     drop parent spec
  37.     if( _VREPrimaryWindow == "" )then do
  38.         call VRMessage "", "Cannot load window:" VRError(), ,
  39.             "Error!"
  40.         _VREReturnValue = 32000
  41.         signal _VRELeaveMain
  42.     end
  43. */
  44.  
  45. /*  Process events
  46. */
  47.     call Init
  48.     signal on halt
  49.     do forever
  50. /*    do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) ) */
  51.         _VREEvent = VREvent()
  52.         interpret _VREEvent
  53.     end
  54. _VREHalt:
  55.     _VREReturnValue = Fini()
  56.  
  57. /*
  58.     call VRDestroy _VREPrimaryWindow
  59. */
  60.  
  61. _VRELeaveMain:
  62.     call VRFini
  63. exit _VREReturnValue
  64.  
  65. /*
  66. VRLoadSecondary: procedure
  67.     name = arg( 1 )
  68.  
  69.     window = VRLoad( VRWindow(), VRWindowPath(), name )
  70.     call VRMethod window, "CenterWindow"
  71.     call VRSet window, "Visible", 1
  72.     call VRMethod window, "Activate"
  73. return window
  74. */
  75. /*:VRX         AddFileInfo
  76. */
  77. AddFileInfo: 
  78.     RemFileList = VRGetIni( "VxFTP", "RemFileList", IniFile, "NoClose" )
  79.  
  80.     select
  81.         /* Include Size, not Date                   */
  82.         when substr( RemFileList, 2, 2 ) = '10' then
  83.             do i = 1 to remote_file.0
  84.                 if length( remote_file.i) < 12 then
  85.                     remote_file.i = remote_file.i || copies( ' ', 12-length(remote_file.i))
  86.                 remote_file.i = remote_file.i '|' remote_size.i
  87.             end
  88.  
  89.         /* Include Date not Size                   */
  90.         when substr( RemFileList, 2, 2 ) = '01' then
  91.             if ( SysType = "UNIX" | SysType = "NW" ) then
  92.                 do i = 1 to remote_file.0
  93.                     if length( remote_file.i) < 12 then
  94.                         remote_file.i = remote_file.i || copies( ' ', 12-length(remote_file.i))
  95.                     remote_file.i = remote_file.i '|' remote_date.i remote_time.i
  96.                 end
  97.             else 
  98.                 do i = 1 to remote_file.0
  99.                     if length( remote_file.i) < 12 then
  100.                         remote_file.i = remote_file.i || copies( ' ', 12-length(remote_file.i))
  101.                     remote_file.i = remote_file.i '|' remote_date.i
  102.                 end
  103.  
  104.         /* Include Size, include Date              */
  105.         when substr( RemFileList, 2, 2 ) = '11' then
  106.             if ( SysType = "UNIX" | SysType = "NW" ) then
  107.                 do i = 1 to remote_file.0
  108.                     if length( remote_file.i) < 12 then
  109.                         remote_file.i = remote_file.i || copies( ' ', 12-length(remote_file.i))
  110.                     remote_file.i = remote_file.i '|' remote_size.i '|' remote_date.i remote_time.i
  111.                 end
  112.             else
  113.                 do i = 1 to remote_file.0
  114.                     if length( remote_file.i) < 12 then
  115.                         remote_file.i = remote_file.i || copies( ' ', 12-length(remote_file.i))
  116.                     remote_file.i = remote_file.i '|' remote_size.i '|' remote_date.i
  117.                 end
  118.  
  119.         otherwise
  120.             nop
  121.     end
  122.  
  123.  
  124. return
  125.  
  126. /*:VRX         AddToDirCache
  127. */
  128. AddToDirCache: 
  129.     
  130.     TableIndex = (TableIndex // MaxTableSize ) + 1
  131.     if ( TableIndex > TableSize ) then
  132.         TableSize = TableIndex
  133.  
  134.     Table.Dir_Name.TableIndex = GRemotePath
  135.     Table.Freshness.TableIndex = 'FRESH'
  136.  
  137.     /* The user may want to view the names of the directories cached,
  138.      * so publish the new one to the Local thread so it can be added
  139.      * to the list.
  140.      */
  141.     Table.Dir_Name.0 = TableSize
  142.     rc = VRMethod( "Application", "PutVar", "Table.Dir_Name." )
  143.     rc = VRMethod( "Application", "PostQueue", 0, 1, "call RefreshCachedDirs" )
  144.  
  145.     Table.CreateTime.TableIndex = time(minutes)
  146.     do i = 1 to remote_file.0
  147.         Table.files.TableIndex.i = remote_file.i
  148.         Table.dates.TableIndex.i = remote_date.i
  149.         Table.sizes.TableIndex.i = remote_size.i
  150.         Table.times.TableIndex.i = remote_time.i
  151.     end
  152.     Table.files.TableIndex.0 = remote_file.0
  153.     Table.dates.TableIndex.0 = remote_file.0
  154.     Table.sizes.TableIndex.0 = remote_file.0
  155.     Table.times.TableIndex.0 = remote_file.0
  156.  
  157.     do i = 1 to remote_dir.0
  158.         Table.dirs.TableIndex.i = remote_dir.i
  159.     end
  160.     Table.dirs.TableIndex.0 = remote_dir.0
  161.  
  162.     drop i
  163. return
  164.  
  165. /*:VRX         BasicErrMsg
  166. */
  167. BasicErrMsg:
  168.     parse arg ErrMessage
  169.  
  170.     OK = 1
  171.     Buttons.OK = "OK"
  172.     Cancel = 2
  173.     Buttons.Cancel = "Cancel"
  174.     Buttons.0 = 2
  175.     
  176.     id = VRMessage( VRWindow(), ErrMessage, "Error", ,
  177.                      "Error", "Buttons.", OK, Cancel )
  178. return
  179.  
  180. /*:VRX         ChangeToRemoteFSComplete
  181. */
  182. ChangeToRemoteFSComplete: 
  183.     /* Check how to update remote lists and update directory cache     */
  184.     UseCache = VRGetIni( "VxFTP", "UseCache", IniFile, "NoClose" )
  185.     NoRefresh = VRGetIni( "VxFTP", "NoRemoteUpdate", IniFile, "NoClose" )
  186.     select
  187.         when ( UseCache = 1 & NoRefresh = 0 ) then do
  188.             rc = VRMethod( "Application", "PostQueue", 0, 1, "call RefreshRemote" )
  189.             call RefreshRemoteLists
  190.           end
  191.  
  192.         when ( UseCache = 1 & NoRefresh = 1 ) then
  193.             call MarkCacheEntryStale
  194.  
  195.         when ( UseCache = 0 & NoRefresh = 0 ) then do
  196.             rc = VRMethod( "Application", "PostQueue", 0, 1, "call RefreshRemote" )
  197.             call DownloadNParseList
  198.           end
  199.  
  200.         otherwise
  201.             nop
  202.     end /* select */
  203.  
  204.     drop UseCache NoRefresh
  205. return
  206.  
  207. /*:VRX         DownloadNParseList
  208. */
  209. DownloadNParseList: 
  210.     /* Get the remote directory listing, parse it, and put
  211.      * the remote directory and file listings in Global memory
  212.      * for the GUI thread (main thread) to access.
  213.      */
  214.     TextToSend = 'call VRSet "MainWindow", "StatusText", "Downloading file list"'
  215.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  216.  
  217.     RemFileList = VRGetIni( "VxFTP", "RemFileList", IniFile, "NoClose" )
  218.     if ( left( RemFileList, 1 ) = 'L' ) then do
  219.         if ( SysType = "VMS" ) then
  220.             rc = FtpLs( " ", remote_list. )
  221.         else
  222.             rc = FtpLs( ".", remote_list. )
  223.  
  224.         if (rc = 1) then
  225.             call FtpErrMsg
  226.         else do
  227.             do i = 1 to remote_list.0
  228.                 remote_file.i = remote_list.i
  229.             end
  230.             remote_file.0 = i-1
  231.             remote_size.0 = 0
  232.             remote_date.0 = 0
  233.             remote_time.0 = 0
  234.             remote_dir.0  = 0
  235.             call PostRemoteFiles
  236.         end
  237.       end
  238.  
  239.     else do
  240.         if ( SysType = "VMS" ) then
  241.             rc = FtpDir( " ", remote_list. )
  242.         else
  243.             rc = FtpDir( ".", remote_list. )
  244.  
  245.         if (rc = 1) then
  246.             call FtpErrMsg
  247.         else do
  248.             command = "call ParseRemoteFileList"SysType
  249.             interpret command
  250.             call AddFileInfo
  251.             call PostRemoteFiles
  252.         end
  253.     end
  254.  
  255.     TextToSend = 'call VRSet "MainWindow", "StatusText", " "'
  256.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  257.  
  258.  
  259. return
  260.  
  261. /*:VRX         Fini
  262. */
  263. Fini:
  264. /* This code is not needed since the Window is never made visible. */
  265. /*
  266.     window = VRWindow()
  267.     call VRSet window, "Visible", 0 
  268.     drop window
  269. */
  270. return 0
  271.  
  272. /*:VRX         FTP_Logoff
  273. */
  274. FTP_Logoff:
  275.     rc = FtpLogoff()
  276.     if (rc <> 0) then
  277.         call FTPErrMsg
  278.  
  279.     else do
  280.         drop SysType Host Login Passwd rCWD VMS_ListingType
  281.         call VRMethod "Application", "PostQueue", 1, 0,,
  282.              "call LogoffSuccessful"
  283.  
  284.         call VRMethod "Application", "PostQueue", 1, 0,,
  285.              'call VRSet "MainWindow", "StatusText", "Logoff was successful"'
  286.  
  287.         remote_file.0 = 0
  288.         remote_size.0 = 0
  289.         remote_date.0 = 0
  290.         remote_time.0 = 0
  291.         remote_dir.0  = 0
  292.         call VRMethod "Application", "PutVar", "remote_file."
  293.         call VRMethod "Application", "PutVar", "remote_size."
  294.         call VRMethod "Application", "PutVar", "remote_date."
  295.         call VRMethod "Application", "PutVar", "remote_time."
  296.         call VRMethod "Application", "PutVar", "remote_dir."
  297.  
  298.         call SetupDirCacheTable
  299.     end /* end else */
  300. return
  301.  
  302. /*:VRX         FTPChangeDir
  303. */
  304. FTPChangeDir:
  305.     /* Change directory on the remote host
  306.      */
  307.     newPath = VRInfo("newDir")
  308.  
  309.     TextToSend = 'call VRSet "MainWindow", "StatusText", "Changing to' newPath'"'
  310.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  311.  
  312.     rc = FtpChDir(newPath)
  313.     if (rc <> 0) then do
  314.         call FTPErrMsg
  315.         call VRMethod "Application", "PostQueue", 0, 1, ,
  316.              "call EnableRemoteLists"
  317.         return -1
  318.     end
  319.  
  320.     call SetRemotePath           /* Get value for GRemotePath       */
  321.     call SetRemoteCWD            /* Determine & post Remote CWD     */
  322.     call RemoteDirList           /* Get, parse, & post files & dirs */
  323.  
  324.     drop newPath
  325. return
  326.  
  327. /*:VRX         FTPDeleteFiles
  328. */
  329. FTPDeleteFiles:
  330.     /* Get the list of files to delete, then delete them one at a time.
  331.      */
  332.     call VRMethod "Application", "GetVar", "deleteFiles."
  333.  
  334.     do i = 1 to deleteFiles.0
  335.         TextToSend = 'call VRSet "MainWindow", "StatusText", "Deleting' deleteFiles.i'"'
  336.         rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  337.  
  338.         rc = FtpDelete( deleteFiles.i )
  339.         if (FTPERRNO <> 0) then  call FTPErrMsg
  340.     end /* do */
  341.  
  342.     TextToSend = 'call VRSet "MainWindow", "StatusText", " "'
  343.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  344.  
  345.     rc = VRMethod( "Application", "PostQueue", 0, 1, "call EnableRemoteLists" )
  346.  
  347.     call ChangeToRemoteFSComplete
  348.  
  349.     drop NoUpdate
  350. return
  351.  
  352. /*:VRX         FTPErrMsg
  353. */
  354. FTPErrMsg:
  355.     call VRMethod "Application", "PostQueue", 0, 1, "call FTPErrMsg", ,
  356.          "FTP_Errno", FTPERRNO
  357.  
  358. return
  359.  
  360. /*:VRX         FTPMakeDir
  361. */
  362. FTPMakeDir:
  363.     newPath = VRInfo("newDir")
  364.  
  365.     rc = FtpMkDir(newPath)
  366.     if (rc <> 0) then do
  367.         call FTPErrMsg
  368.         call VRMethod "Application", "PostQueue", 0, 1, ,
  369.              "call EnableRemoteLists"
  370.         return -1
  371.     end
  372.  
  373.     call ChangeToRemoteFSComplete
  374.  
  375.     drop newPath
  376. return
  377.  
  378. /*:VRX         FTPRemoveDir
  379. */
  380. FTPRemoveDir:
  381.     removePath = VRInfo("removeDir")
  382.  
  383.     rc = FtpRmDir(removePath)
  384.     if (rc <> 0) then do
  385.         call FTPErrMsg
  386.         call VRMethod "Application", "PostQueue", 0, 1, ,
  387.              "call EnableRemoteLists"
  388.         return -1
  389.     end
  390.  
  391.     call ChangeToRemoteFSComplete
  392.  
  393.     drop removePath
  394. return
  395.  
  396. /*:VRX         FTPRenameFiles
  397. */
  398. FTPRenameFiles:
  399.     /* Get the list of files to rename, then rename them one at a time.
  400.      */
  401.     call VRMethod "Application", "GetVar", "renameFiles."
  402.  
  403.     /* HOWARD, do not remove 'DoRefresh'. It's used below the DO-Loop
  404.      */
  405.     DoRefresh = 'FALSE'
  406.     do i = 1 to renameFiles.0
  407.         RenamedFile = PromptDlg( "Rename Local File", ,
  408.                                  "Rename" renameFiles.i, ,
  409.                                  renameFiles.i )
  410.  
  411.         if ( RenamedFile = "") then
  412.             iterate
  413.         else
  414.             DoRefresh = 'TRUE'
  415.  
  416.         rc = FtpRename( renameFiles.i, RenamedFile )
  417.         if ( FTPERRNO <> 0 ) then  call FTPErrMsg
  418.     end /* do */
  419.  
  420.     rc = VRMethod( "Application", "PostQueue", 0, 1, "call EnableRemoteLists" )
  421.  
  422.     if ( DoRefresh = 'TRUE' ) then
  423.         call ChangeToRemoteFSComplete
  424.  
  425. return
  426.  
  427. /*:VRX         GetFilesNoRename
  428. */
  429. GetFilesNoRename:
  430.     rc = VRMethod( "Application", "GetVar", "getFiles." )
  431.     rc = VRMethod( "Application", "GetVar", "getFilesSize." )
  432.  
  433.     do i = 1 to getFiles.0
  434.         local_file = getFiles.i
  435.  
  436.         /* If user has indicated to show download progress, then start thread
  437.          * that monitors that; else, just download the file
  438.          */
  439.         if ( VRGetIni( "VxFTP", "ProgInd", IniFile, "NoClose" ) = "1" ) then do
  440.             call SpawnXferProgress local_file getFilesSize.i
  441.             rc = FtpGet( local_file, getFiles.i, XferType )
  442.             rc = VRMethod( "Application", "HaltThread", XferProgTID )
  443.             if (rc = 1) then
  444.                 call BasicErrMsg "Couldn't kill XferThread" XferProgTID
  445.           end
  446.         else do
  447.             TextToSend = 'call VRSet "MainWindow", "StatusText", "Getting ""' || getFiles.i || '"" "'
  448.             rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  449.             rc = FtpGet( local_file, getFiles.i, XferType )
  450.         end
  451.  
  452.         if (FTPERRNO <> 0) then
  453.             call FTPErrMsg
  454.         else do
  455.             comments = "Downloaded from" Host "from" GRemotePath "using VxFTP on" Date('L') "at" Time('Civil')
  456.             comments = 'DFFF00000100FDFF'x || d2c( length(comments)) || '00'x || comments
  457.             call SysPutEA local_file, ".COMMENTS", comments
  458.         end 
  459.     end /* do */
  460.  
  461.     rc = VRMethod( "Application", "PostQueue", 0, 1, ,
  462.         'call GetComplete' )
  463.  
  464. return
  465.  
  466. /*:VRX         GetFilesRenamed
  467. */
  468. GetFilesRenamed:
  469.     rc = VRMethod( "Application", "GetVar", "getFiles." )
  470.     rc = VRMethod( "Application", "GetVar", "getFilesSize." )
  471.  
  472.     do i = 1 to getFiles.0
  473.         local_file = PromptDlg( "Get with Renaming", ,
  474.                                 "Get" getFiles.i "as..", getFiles.i )
  475.  
  476.         if ( local_file = "" ) then
  477.             iterate
  478.  
  479.         /* If user has indicated to show download progress, then start thread
  480.          * that monitors that; else, just download the file
  481.          */
  482.         if ( VRGetIni( "VxFTP", "ProgInd", IniFile, "NoClose" ) = "1" ) then do
  483.             call SpawnXferProgress local_file getFilesSize.i
  484.             rc = FtpGet( local_file, getFiles.i, XferType )
  485.             rc = VRMethod( "Application", "HaltThread", XferProgTID )
  486.             if (rc = 1) then
  487.                 call BasicErrMsg "Couldn't kill XferThread" XferProgTID
  488.           end
  489.         else do
  490.             TextToSend = 'call VRSet "MainWindow", "StatusText", "Getting ""' || getFiles.i || '"" as ""' || local_file || '"" "'
  491.             rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  492.             rc = FtpGet( local_file, getFiles.i, XferType )
  493.         end
  494.  
  495.         if (FTPERRNO <> 0) then
  496.             call FTPErrMsg
  497.         else do
  498.             comments = "Downloaded" getFiles.i "from" Host "from" GRemotePath "using VxFTP on" Date('L') "at" Time('Civil')
  499.             comments = 'DFFF00000100FDFF'x || d2c( length(comments)) || '00'x || comments
  500.             call SysPutEA local_file, ".COMMENTS", comments
  501.         end 
  502.     end /* do */
  503.  
  504.     rc = VRMethod( "Application", "PostQueue", 0, 1, ,
  505.         'call GetComplete' )
  506.     
  507. return
  508.  
  509. /*:VRX         Halt
  510. */
  511. Halt:
  512.     signal _VREHalt
  513. return
  514.  
  515. /*:VRX         Init
  516. */
  517. Init:
  518.     signal on syntax name syntax_handler
  519.     FTPFuncsLoaded = 'NO'
  520.     if RxFuncQuery("FtpLoadFuncs") then
  521.         do
  522.         rc = RxFuncAdd("FtpLoadFuncs", "RxFtp", "FtpLoadFuncs")
  523.         rc = FtpLoadFuncs()
  524.     end
  525.     FTPFuncsLoaded = 'YES'
  526.  
  527.     /* Get the path to the VxFTP .ini file                           */
  528.     rc = VRMethod( "Application", "GetVar", "IniFile"  )
  529.  
  530.     /* Have the UserInterface side display the Login dialog box      */
  531.     rc = VRMethod("Application", "PostQueue", 0, 1, "call GetLoginInfo")
  532.  
  533.     call SetupDirCacheTable
  534.     XferType = VRGetIni( "VxFTP", "XferType", IniFile, "NoClose" )
  535.  
  536.     drop window
  537. return
  538.  
  539. /*:VRX         LogonToHost
  540. */
  541. LogonToHost:
  542.     Host    = VRInfo( "Host" )
  543.     Login   = VRInfo( "Login" )
  544.     Passwd  = VRInfo( "Passwd" )
  545.     rCWD    = VRInfo( "rCWD" )
  546.     Anon    = VRInfo( "Anon" )
  547.     SysType = VRInfo( "SysType" )
  548.  
  549.     /* Put firewall information here */
  550.     rc = FtpSetUser(Host, Login, Passwd)
  551.     if ( rc = 0 ) then
  552.         call BasicErrMsg "Couldn't set User information."
  553.  
  554.     rc = FtpPwd( junk )     /* Verify connection & get remote host's current PWD */
  555.     if (rc = -1) then do
  556.         if ( FTPERRNO = "FTPLOGIN" ) then
  557.             if ( VRGetIni( "VxFTP", "UseTimer", IniFile, "NoClose" ) = 1 ) then do
  558.                 rc = VRMethod( "Application", "PostQueue", 0, 1, ,
  559.                      "call LoginAttemptFailed" )
  560.                 return -1
  561.             end
  562.         else do
  563.             rc = VRMethod( "Application", "PostQueue", 0, 1, ,
  564.                  "call LogoffSuccessful" )
  565.             call FTPErrMsg
  566.         end
  567.         return -1
  568.     end
  569.  
  570.     TextToSend = 'call VRSet "MainWindow", "StatusText", "Successfully connected to' Host '"'
  571.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  572.  
  573.     /* Find out the size of the cache table that the user specified  */
  574.     MaxTableSize = VRGetIni( "VxFTP", "CacheSize", IniFile, "NoClose" )
  575.  
  576.     /* If user specified a directory, change to it          */
  577.     if (rCWD <> "" ) then do
  578.         rc = FtpChDir(rCWD)
  579.         if (rc = -1) then
  580.             call BasicErrMsg "Couldn't change to remote directory specified."
  581.     end
  582.  
  583.     /* Find out system type                                */
  584.     if ( SysType = 'auto detect' ) then do
  585.         drop SysType     /*  Drop SysType so that call to FtpSys works properly  */
  586.         rc = FtpSys( SysType )
  587.         select
  588.             when ( translate( left( SysType,4 ) = "UNIX" )) then do
  589.                 SysType = "UNIX"
  590.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysUNIX_Click" )
  591.               end
  592.             when ( translate( left( SysType,4 ) = "OS/2" )) then do
  593.                 SysType = "PC"
  594.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysOS2_Click" )
  595.               end
  596.             when ( translate( left( SysType,3 ) = "VMS" )) then do
  597.                 SysType = "VMS"
  598.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysVMS_Click" )
  599.               end
  600.             when ( SysType = "Windows_NT version 3.50" ) then do
  601.                 SysType = "NT"
  602.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysNT_Click" )
  603.               end
  604.             when ( translate( left( SysType,5 ) = "MACOS" )) then do
  605.                 SysType = "MAC"
  606.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysMac_Click" )
  607.               end
  608.             when ( translate( left( SysType,2 ) = "VM" )) then do
  609.                 SysType = "VM"
  610.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysVM_Click" )
  611.               end
  612.             otherwise
  613.                 SysType = "UNIX"
  614.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysUnknown_Click" )
  615.  
  616.         end /* select */
  617.  
  618.      end /* if */
  619.     else 
  620.         select
  621.             when ( SysType = 'OS/2' )      then do
  622.                 SysType = "PC"
  623.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysOS2_Click" )
  624.               end
  625.             when ( SysType = 'UNIX' )      then
  626.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysUNIX_Click" )
  627.  
  628.             when ( SysType = 'Windows NT' )      then do
  629.                 SysType = "NT"
  630.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysNT_Click" )
  631.               end
  632.  
  633.             when ( SysType = 'NetWare' )   then do
  634.                 SysType = "NW" 
  635.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysNW_Click" )
  636.               end
  637.             when ( SysType = 'VAX VMS' )   then do
  638.                 SysType = "VMS"
  639.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysVMS_Click" )
  640.               end
  641.             when ( SysType = 'IBM VM' )    then do
  642.                 SysType = "VM"
  643.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysVM_Click" )
  644.               end
  645.             when ( SysType = 'Macintosh' ) then do
  646.                 SysType = "MAC"
  647.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysMac_Click" )
  648.               end
  649.             otherwise
  650.                 SysType = "UNIX"
  651.                 rc = VRMethod( "Application", "PostQueue", 0, 1, "call MI_SysUnknown_Click" )
  652.         end /* select */
  653.     
  654.     /* Enable buttons and menus appropriately     */
  655.     rc = VRMethod( "Application", "PostQueue", 0, 1, "call LogonSuccessful" )
  656.  
  657.     call SetRemotePath           /* Get value for GRemotePath       */
  658.     call SetRemoteCWD            /* Determine & post Remote CWD     */
  659.     call RemoteDirList           /* Get, parse, & post files & dirs */
  660.  
  661. return
  662. /*:VRX         MarkCacheEntryStale
  663. */
  664. MarkCacheEntryStale: 
  665.     do i = 1 to TableSize
  666.         if Table.Dir_Name.i = GRemotePath then do
  667.             Table.Freshness.i = 'STALE'
  668.             leave
  669.         end
  670.     end
  671. return
  672.  
  673. /*:VRX         ParseRemoteCWD_MAC
  674. */
  675. ParseRemoteCWD_MAC:
  676.     /* This routine extracts the directories from the RemotePath, placing
  677.        them in a stem variable, RemoteCWDDirs.
  678.      */
  679.     remDirs = translate(GRemotePath, '*', ' ')
  680.     remDirs = translate(remDirs, ' ', '/')
  681.     remDirs = "/ " || remDirs
  682.     numDirs = words(remDirs)
  683.     RemoteCWDDirs.0 = numDirs 
  684.  
  685. return
  686.  
  687. /*:VRX         ParseRemoteCWD_NT
  688. */
  689. ParseRemoteCWD_NT: 
  690.     call ParseRemoteCWD_PC
  691. return
  692.  
  693. /*:VRX         ParseRemoteCWD_NW
  694. */
  695. ParseRemoteCWD_NW:
  696.     /* This routine extracts the directories from the RemotePath, placing
  697.        them in a stem variable, RemoteDirs.; It then places RemoteDirs. into
  698.        global memory for the GUI (main) thread access.
  699.      */
  700.     remDirs = translate(GRemotePath, '*', ' ')
  701.     remDirs = translate(remDirs, ' ', '\')
  702.     remDirs = translate(remDirs, ' ', '/')
  703.     remDirs = '/ ' || remDirs
  704.     numDirs = words(remDirs)
  705.     RemoteCWDDirs.0 = numDirs 
  706.  
  707. return
  708.  
  709. /*:VRX         ParseRemoteCWD_PC
  710. */
  711. ParseRemoteCWD_PC:
  712.     /* This routine extracts the directories from the RemotePath, placing
  713.        them in a stem variable, RemoteDirs.; It then places RemoteDirs. into
  714.        global memory for the GUI (main) thread access.
  715.      */
  716.  
  717.     remDirs = translate(GRemotePath, '*', ' ')
  718.     remDirs = translate(remDirs, ' ', '\')
  719.     remDirs = translate(remDirs, ' ', '/')
  720.     numDirs = words(remDirs)
  721.     RemoteCWDDirs.0 = numDirs 
  722.  
  723. return
  724.  
  725. /*:VRX         ParseRemoteCWD_UNIX
  726. */
  727. ParseRemoteCWD_UNIX:
  728.     /* This routine extracts the directories from the RemotePath, placing
  729.        them in a stem variable, RemoteCWDDirs.
  730.      */
  731.     remDirs = translate(GRemotePath, '*', ' ')
  732.     remDirs = translate(remDirs, ' ', '/')
  733.     remDirs = "/ " || remDirs
  734.     numDirs = words(remDirs)
  735.     RemoteCWDDirs.0 = numDirs 
  736.  
  737. return
  738.  
  739. /*:VRX         ParseRemoteCWD_VM
  740. */
  741. ParseRemoteCWD_VM:
  742.     remDirs = GRemotePath
  743.     numDirs = 1
  744.     RemoteCWDDirs.0 = 1    
  745. return
  746.  
  747. /*:VRX         ParseRemoteCWD_VMS
  748. */
  749. ParseRemoteCWD_VMS:
  750.     /* This routine extracts the directories from the RemotePath, placing
  751.      * them in a stem variable, RemoteCWDDirs.
  752.      */
  753.     remDirs = translate( GRemotePath, '.', ']' )
  754.     remDirs = translate( remDirs, ' ', '[' )
  755.     remDirs = translate( remDirs, ' ', '.' )
  756.     numDirs = words( remDirs )
  757.     RemoteCWDDirs.0 = numDirs 
  758.  
  759. return
  760.  
  761. /*:VRX         ParseRemoteFileListMAC
  762. */
  763. ParseRemoteFileListMAC:
  764.     k = 0
  765.     j = 0
  766.     do i = 1 to remote_list.0
  767.         select 
  768.             when (left(remote_list.i, 1) = "-") then
  769.                 do
  770.                 k = k+1
  771.                 parse value remote_list.i with type1 nbr remote_size.k resource month day remote_time.k remote_file.k
  772.                 remote_date.k = month day
  773.                 end
  774.  
  775.             when (left(remote_list.i, 1) = "d") then
  776.                 do
  777.                 j = j+1
  778.                 parse value remote_list.i with type1 folder resource month day time remote_dir.j 
  779.                 end
  780.  
  781.             otherwise
  782.                 iterate
  783.         end /* end select */
  784.     end /* end do */
  785.  
  786.     remote_file.0 = k
  787.     remote_size.0 = k
  788.     remote_date.0 = k
  789.     remote_time.0 = k
  790.     remote_dir.0 = j
  791.  
  792. return
  793.  
  794. /*:VRX         ParseRemoteFileListNT
  795. */
  796. ParseRemoteFileListNT: 
  797.     k = 0
  798.     j = 0
  799.     do i = 1 to remote_list.0
  800.         parse value remote_list.i with junk1 junk2 size junk3
  801.  
  802.         if ( datatype( size, Number ) = 1 ) then do
  803.             k = k+1
  804.             parse value remote_list.i with remote_date.k remote_time.k remote_size.k remote_file.k
  805.           end
  806.         else do
  807.             j = j+1
  808.             parse value remote_list.i with junk1 junk2 junk3 directory
  809.             remote_dir.j = strip( directory ) 
  810.         end
  811.  
  812.     end /* end do */
  813.  
  814.     remote_file.0 = k
  815.     remote_size.0 = k
  816.     remote_date.0 = k
  817.     remote_time.0 = k
  818.     remote_dir.0 = j
  819.  
  820.  
  821. return
  822.  
  823. /*:VRX         ParseRemoteFileListNW
  824. */
  825. ParseRemoteFileListNW:
  826.     k = 0
  827.     j = 0
  828.     do i = 1 to remote_list.0
  829.         select 
  830.             when (left(remote_list.i, 1) = "-") then
  831.                 do
  832.                 k = k+1
  833.                 parse value remote_list.i with type1 nbr poster remote_size.k month day remote_time.k remote_file.k
  834.                 remote_date.k = month day
  835.                 end
  836.             when (left(remote_list.i, 1) = "d") then
  837.                 do
  838.                 j = j+1
  839.                 parse value remote_list.i with type1 nbr poster size month day time remote_dir.j 
  840.                 end
  841.             when (left(remote_list.i, 1) = "l") then
  842.                 do
  843.                 j = j+1
  844.                 parse value remote_list.i with type1 nbr poster size month day time link arrow remote_dir.j 
  845.                 end
  846.             otherwise
  847.                 iterate
  848.         end /* end select */
  849.     end /* end do */
  850.  
  851.     remote_file.0 = k
  852.     remote_size.0 = k
  853.     remote_date.0 = k
  854.     remote_time.0 = k
  855.     remote_dir.0 = j
  856.  
  857. return
  858.  
  859. /*:VRX         ParseRemoteFileListPC
  860. */
  861. ParseRemoteFileListPC:
  862.     k = 0
  863.     j = 0
  864.     do i = 1 to remote_list.0
  865.     parse value remote_list.i with size pos2 rest
  866.         select 
  867.             when ( pos2 = "DIR") then
  868.                 do
  869.                 parse value remote_list.i with size dir date time dirname
  870.                 dirname = strip(dirname)
  871.                 if (dirname == ".") then
  872.                     iterate
  873.                 k = k+1
  874.                 remote_dir.k = dirname
  875.                 end
  876.  
  877.             otherwise
  878.                 do
  879.                 parse value remote_list.i with size rest
  880.                 attrib = left( strip(rest), 1)
  881.                 if ( attrib = "A" ) | ( attrib = "R" ) then
  882.                     parse value rest with attrib date time filename
  883.                 else
  884.                     parse value rest with date time filename
  885.  
  886.                 j = j+1
  887.                 remote_file.j = strip( filename )
  888.                 remote_size.j = strip( size )
  889.                 remote_date.j = strip( date )
  890.                 remote_time.j = strip( time )
  891.                 end
  892.  
  893.         end /* end select */
  894.     end /* end do */
  895.  
  896.     remote_file.0 = j
  897.     remote_size.0 = j
  898.     remote_date.0 = j
  899.     remote_time.0 = j
  900.     remote_dir.0 = k
  901.  
  902. return
  903.  
  904. /*:VRX         ParseRemoteFileListUNIX
  905. */
  906. ParseRemoteFileListUNIX:
  907.     k = 0
  908.     j = 0
  909.     do i = 1 to remote_list.0
  910.         select 
  911.             when (left(remote_list.i, 1) = "-") then
  912.                 do
  913.                 k = k+1
  914.                 parse value remote_list.i with type1 nbr poster stuff remote_size.k month day remote_time.k remote_file.k
  915.                 remote_file.k = strip( remote_file.k )
  916.                 remote_date.k = month day
  917.                 end
  918.             when (left(remote_list.i, 1) = "d") then
  919.                 do
  920.                 j = j+1
  921.                 parse value remote_list.i with type1 nbr poster stuff size month day time remote_dir.j 
  922.                 remote_dir.j = strip( remote_dir.j )
  923.                 end
  924.             when (left(remote_list.i, 1) = "l") then
  925.                 do
  926.                 j = j+1
  927.                 parse value remote_list.i with type1 nbr poster stuff size month day time link arrow remote_dir.j 
  928.                 remote_dir.j = strip( remote_dir.j )
  929.                 end
  930.             otherwise
  931.                 iterate
  932.         end /* end select */
  933.     end /* end do */
  934.  
  935.     remote_file.0 = k
  936.     remote_size.0 = k
  937.     remote_date.0 = k
  938.     remote_time.0 = k
  939.     remote_dir.0 = j
  940. return
  941.  
  942. /*:VRX         ParseRemoteFileListVM
  943. */
  944. ParseRemoteFileListVM:
  945.     do i = 1 to remote_list.0
  946.         parse value remote_list.i with filename type format lrecl remote_size.i blocks remote_date.i remote_time.i
  947.         remote_file.i = strip( filename ) || "." || strip( type )
  948.     end
  949.  
  950.     remote_file.0 = i - 1
  951.     remote_size.0 = i - 1
  952.     remote_date.0 = i - 1
  953.     remote_time.0 = i - 1
  954. return
  955.  
  956. /*:VRX         ParseRemoteFileListVMS
  957. */
  958. ParseRemoteFileListVMS:
  959. j = 0
  960. k = 0
  961. if ( VMS_ListingType = "VMS_LISTINGTYPE" ) then do
  962.     do i = 1 to remote_list.0
  963.         remote_list.i = strip( remote_list.i )
  964.  
  965.         if ( remote_list.i <> "" ) then do
  966.             /* The key here is the semicolon in this parse command. All (let's hope)
  967.              * VMS listings have a semi-colon in the filename to denote the version of
  968.              * that file. If the line in remote_list isn't a real file or directory
  969.              * the subsequent variables will be NULL, so we can iterate up.
  970.              */
  971.             parse value remote_list.i with filename ";" num pos1 pos2 pos3 pos4 pos5
  972.             if ( pos1 = "" ) then
  973.                 iterate
  974.             select 
  975.                 when pos( 'JAN', pos1 ) > 0 then pos1 = 'date'
  976.                 when pos( 'FEB', pos1 ) > 0 then pos1 = 'date'
  977.                 when pos( 'MA',  pos1 ) > 0 then pos1 = 'date'    
  978.                 when pos( 'APR', pos1 ) > 0 then pos1 = 'date'
  979.                 when pos( 'JU',  pos1 ) > 0 then pos1 = 'date'
  980.                 when pos( 'AUG', pos1 ) > 0 then pos1 = 'date'
  981.                 when pos( 'SEP', pos1 ) > 0 then pos1 = 'date'    
  982.                 when pos( 'OCT', pos1 ) > 0 then pos1 = 'date'
  983.                 when pos( 'NOV', pos1 ) > 0 then pos1 = 'date'
  984.                 when pos( 'DEC', pos1 ) > 0 then pos1 = 'date'    
  985.                 when pos( 'JAN', pos3 ) > 0 then pos3 = 'date'
  986.                 when pos( 'FEB', pos3 ) > 0 then pos3 = 'date'
  987.                 when pos( 'MA',  pos3 ) > 0 then pos3 = 'date'    
  988.                 when pos( 'APR', pos3 ) > 0 then pos3 = 'date'
  989.                 when pos( 'JU',  pos3 ) > 0 then pos3 = 'date'
  990.                 when pos( 'AUG', pos3 ) > 0 then pos3 = 'date'
  991.                 when pos( 'SEP', pos3 ) > 0 then pos3 = 'date'    
  992.                 when pos( 'OCT', pos3 ) > 0 then pos3 = 'date'
  993.                 when pos( 'NOV', pos3 ) > 0 then pos3 = 'date'
  994.                 when pos( 'DEC', pos3 ) > 0 then pos3 = 'date'    
  995.                 otherwise nop   
  996.             end /* select */
  997.             select
  998.                 when pos( ':', pos1 ) > 0 then pos1 = 'time'
  999.                 when pos( ':', pos2 ) > 0 then pos2 = 'time'
  1000.                 when pos( ':', pos3 ) > 0 then pos3 = 'time'
  1001.                 when pos( ':', pos4 ) > 0 then pos4 = 'time'
  1002.                 otherwise nop
  1003.             end /* select */
  1004.         leave      /* exit the do-loop once we've got a legit file list entry */
  1005.         end /* if */
  1006.     end /* do */
  1007.  
  1008.     select
  1009.         when ( pos1 = 'date' ) & ( pos2 = 'time' ) then
  1010.             VMS_ListingType = 1
  1011.         when ( pos3 = 'date' ) & ( pos4 = 'time' ) then
  1012.             VMS_ListingType = 2
  1013.         otherwise
  1014.             VMS_ListingType = 2
  1015.     end /* select */
  1016. end /* if */
  1017.  
  1018. do i = 1 to remote_list.0
  1019.     if ( remote_list.i = "" ) then 
  1020.         iterate
  1021.  
  1022.     /* The key here is the semicolon in this parse command. All (let's hope)
  1023.      * VMS listings have a semi-colon in the filename to denote the version of
  1024.      * that file. If the line in remote_list isn't a real file or directory
  1025.      * the subsequent variables will be NULL, so we can iterate up.
  1026.      */
  1027.     remote_list.i = strip( remote_list.i )
  1028.     select
  1029.         when VMS_ListingType = 1 then
  1030.             parse value remote_list.i with filename ";" num date time size "/" blocks attribs
  1031.         when VMS_ListingType = 2 then
  1032.             parse value remote_list.i with filename ";" num size date time owner attribs
  1033.         otherwise
  1034.             parse value remote_list.i with filename ";" num size date time owner attribs
  1035.     end /* select */
  1036.  
  1037.     if ( num = "" ) then 
  1038.         iterate
  1039.     if ( right( translate( filename ), 4) = '.DIR' ) then do
  1040.         j = j + 1
  1041.         length1 = length( strip( filename) )
  1042.         remote_dir.j = left( filename, length1 - 4 )
  1043.     end
  1044.     else do 
  1045.         k = k + 1
  1046.         remote_file.k = strip( filename )
  1047.         remote_size.k = strip( size )
  1048.         remote_date.k = strip( date )
  1049.         remote_time.k = strip( time )
  1050.     end /* else */
  1051. end /* do */
  1052.  
  1053. remote_dir.0  = j
  1054. remote_file.0 = k
  1055. remote_size.0 = k
  1056. remote_date.0 = k
  1057. remote_time.0 = k
  1058.  
  1059. return
  1060.  
  1061. /*:VRX         PB_CacheChange_Click
  1062. */
  1063. PB_CacheChange_Click: 
  1064.     /* This function is called if user chooses a directory from the Cached 
  1065.      * Directories dialog box. 
  1066.      */
  1067.     newPath = VRInfo("newPath")
  1068.  
  1069.     TextToSend = 'call VRSet "MainWindow", "StatusText", "Changing to' newPath'"'
  1070.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1071.  
  1072.     rc = FtpChDir(newPath)
  1073.     if (rc <> 0) then do
  1074.         call FTPErrMsg
  1075.         TextToSend = 'call VRSet "MainWindow", "StatusText", " "'
  1076.         rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1077.         call VRMethod "Application", "PostQueue", 0, 1, ,
  1078.              "call EnableRemoteLists"
  1079.         return -1
  1080.     end
  1081.  
  1082.     call SetRemotePath
  1083.     call SetRemoteCWD
  1084.     call RemoteDirList
  1085.  
  1086.     drop newPath
  1087.  
  1088. return
  1089.  
  1090. /*:VRX         PostRemoteFiles
  1091. */
  1092. PostRemoteFiles: 
  1093.     /* Post the variables to the main, UI thread       */
  1094.     call VRMethod "Application", "PutVar", "remote_file."
  1095.     call VRMethod "Application", "PutVar", "remote_size."
  1096.     call VRMethod "Application", "PutVar", "remote_date."
  1097.     call VRMethod "Application", "PutVar", "remote_time."
  1098.     call VRMethod "Application", "PutVar", "remote_dir."
  1099.     call VRMethod "Application", "PutVar", "remote_list."
  1100.  
  1101.     /* Make main, UI thread act on data just sent      */
  1102.     rc = VRMethod( "Application", "PostQueue", 0, 1, "call SetRemoteDir" )
  1103.  
  1104. return
  1105.  
  1106. /*:VRX         PromptDlg
  1107. */
  1108. PromptDlg: procedure
  1109.     Title = arg(1)
  1110.     Text  = arg(2)
  1111.  
  1112.     if ( arg() = 3 ) then
  1113.         value = arg(3)
  1114.  
  1115.     Buttons.1 = "OK"
  1116.     Buttons.2 = "Cancel"
  1117.     Buttons.0 = 2
  1118.     
  1119.     id = VRPrompt( VRWindow(), Text, "value", Title, "Buttons.", OK, Cancel )
  1120.     if ( id = 2 ) | ( id = 0 ) then
  1121.         return ""
  1122.  
  1123. return value
  1124. /*:VRX         PutFilesNoRename
  1125. */
  1126. PutFilesNoRename:
  1127.     rc = VRMethod( "Application", "GetVar", "putFiles." )
  1128.  
  1129.     do i = 1 to putFiles.0
  1130.         TextToSend = 'call VRSet "MainWindow", "StatusText", "Putting' putFiles.i'"'
  1131.         rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1132.  
  1133.         rc = FtpPut(putFiles.i, putFiles.i, XferType )
  1134.         if (FTPERRNO <> 0) then  call FTPErrMsg
  1135.     end /* do */
  1136.  
  1137.     rc = VRMethod( "Application", "PostQueue", 0, 1, 'call PutComplete' )
  1138.  
  1139.     call ChangeToRemoteFSComplete
  1140. return
  1141.  
  1142. /*:VRX         PutFilesRenamed
  1143. */
  1144. PutFilesRenamed:
  1145.     rc = VRMethod( "Application", "GetVar", "putFiles." )
  1146.  
  1147.     do i = 1 to putFiles.0
  1148.         remote_file = PromptDlg( "Put with Renaming", ,
  1149.                                  "Put" putFiles.i "as..", putFiles.i )
  1150.  
  1151.         TextToSend = 'call VRSet "MainWindow", "StatusText", "Putting ""' || putFiles.i || '"" as ""' || remote_file'"""'
  1152.         rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1153.  
  1154.         rc = FtpPut( putFiles.i, remote_file, XferType )
  1155.         if (FTPERRNO <> 0) then  call FTPErrMsg
  1156.     end /* do */
  1157.  
  1158.     rc = VRMethod( "Application", "PostQueue", 0, 1, 'call PutComplete' )
  1159.  
  1160.     call ChangeToRemoteFSComplete
  1161.  
  1162. return
  1163.  
  1164. /*:VRX         Quit
  1165. */
  1166. Quit:
  1167.     rc = FtpLogoff()
  1168.     rc = FtpDropFuncs()
  1169.     signal _VREHalt
  1170.  
  1171.  /*   window = VRWindow()
  1172.     call VRSet window, "Shutdown", 1
  1173.     drop window
  1174.  */
  1175. return
  1176.  
  1177. /*:VRX         RefreshCacheEntry
  1178. */
  1179. RefreshCacheEntry: 
  1180.     /* Refresh the cache's entry because the Refresh
  1181.      * Interval has expired or because the directory
  1182.      * contents have changed due to user's actions. 
  1183.      */
  1184.  
  1185.     j = arg(1)
  1186.  
  1187.     /* Refresh cached directory entry                 */
  1188.     Table.Freshness.j  = 'FRESH'
  1189.     Table.CreateTime.j = time(minutes)
  1190.     do i = 1 to remote_file.0
  1191.         Table.files.j.i = remote_file.i
  1192.         Table.dates.j.i = remote_date.i
  1193.         Table.sizes.j.i = remote_size.i
  1194.         Table.times.j.i = remote_time.i
  1195.     end
  1196.     Table.files.j.0 = remote_file.0
  1197.     Table.dates.j.0 = remote_file.0
  1198.     Table.sizes.j.0 = remote_file.0
  1199.     Table.times.j.0 = remote_file.0
  1200.  
  1201.     do i = 1 to remote_dir.0
  1202.         Table.dirs.j.i = remote_dir.i
  1203.     end
  1204.     Table.dirs.j.0 = remote_dir.0
  1205.  
  1206.     drop i j
  1207.  
  1208. return
  1209.  
  1210. /*:VRX         RefreshRemoteLists
  1211. */
  1212. RefreshRemoteLists: 
  1213.  
  1214.     do CachedEntryIndex = 1 to TableSize
  1215.         if ( GRemotePath = Table.Dir_Name.CachedEntryIndex ) then do
  1216.             call DownloadNParseList
  1217.             call RefreshCacheEntry CachedEntryIndex
  1218.             leave
  1219.         end
  1220.     end
  1221.  
  1222. return
  1223.  
  1224. /*:VRX         Remote_CWD_Click
  1225. */
  1226. Remote_CWD_Click:
  1227.     selected = VRInfo("selectedDir")
  1228.  
  1229.     /* The stem variable RemoteCWDDirs. is not dropped in SetRemoteCWD,
  1230.      * so we know RemoteCWDDirs.'s values and number of elements.
  1231.      */
  1232.     select
  1233.         when ( SysType = 'VMS' ) then do
  1234.         /* Dios mio! Que esta mierda de VMS me arrecha!! 
  1235.          */
  1236.             last1 = RemoteCWDDirs.0
  1237.             last2 = last1 - 1
  1238.             newPath = RemoteCWDDirs.last1 || "[" || RemoteCWDDirs.last2
  1239.  
  1240.             if ( selected = last1 ) | ( selected = last2) then
  1241.                 newPath = newPath || "]"
  1242.             else do
  1243.                 do i = RemoteCWDDirs.0-2 to selected by -1
  1244.                     newPath = newPath || "." || RemoteCWDDirs.i
  1245.                 end
  1246.                 newPath = newPath || "]"
  1247.             end
  1248.         end /* when VMS */
  1249.  
  1250.         /* Processing for DOS and UNIX machines */
  1251.         Otherwise
  1252.             if selected = RemoteCWDDirs.0 then
  1253.                 newPath = "/"
  1254.             else do
  1255.                 newPath = ""
  1256.                 do i = RemoteCWDDirs.0-1 to selected by -1
  1257.                     newPath = newPath || "/" || RemoteCWDDirs.i
  1258.                 end
  1259.             end
  1260.     end /* select */
  1261.  
  1262.     TextToSend = 'call VRSet "MainWindow", "StatusText", "Changing to' newPath'"'
  1263.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1264.  
  1265.     rc = FtpChDir(newPath)
  1266.     if (rc <> 0) then do
  1267.         call FTPErrMsg
  1268.         call VRMethod "Application", "PostQueue", 0, 1, ,
  1269.              "call EnableRemoteLists"
  1270.         TextToSend = 'call VRSet "MainWindow", "StatusText", "" '
  1271.         rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1272.  
  1273.         return -1
  1274.     end
  1275.  
  1276.     call SetRemotePath
  1277.     call SetRemoteCWD
  1278.     call RemoteDirList
  1279.  
  1280. return
  1281.  
  1282. /*:VRX         Remote_Dir_Combo_DoubleClick
  1283. */
  1284. Remote_Dir_Combo_DoubleClick:
  1285.     newDir = VRInfo("Dir_from_GUI")
  1286.  
  1287.     TextToSend = 'call VRSet "MainWindow", "StatusText", "Changing to' newDir'"'
  1288.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1289.  
  1290.     rc = FtpChDir(newDir)
  1291.     if (rc <> 0) then do
  1292.         call FTPErrMsg
  1293.         call VRMethod "Application", "PostQueue", 0, 1, ,
  1294.              "call EnableRemoteLists"
  1295.         TextToSend = 'call VRSet "MainWindow", "StatusText", "" '
  1296.         rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1297.  
  1298.         return -1
  1299.     end
  1300.  
  1301.     call SetRemotePath
  1302.     call SetRemoteCWD
  1303.     call RemoteDirList
  1304.  
  1305.     drop newDir
  1306. return
  1307.  
  1308. /*:VRX         RemoteDirList
  1309. */
  1310. RemoteDirList:
  1311.     CachedEntryFound = 'FALSE'
  1312.  
  1313.     if ( VRGetIni( "VxFTP", "UseCache", IniFile, "NoClose" ) = 0 ) then 
  1314.         /* If we don't use the Directory Cache, just download & parse */
  1315.         call DownloadNParseList
  1316.     else do
  1317.         do CachedEntryIndex = 1 to TableSize
  1318.             if translate( Table.Dir_Name.CachedEntryIndex ) = translate( GRemotePath ) then do
  1319.                 CachedEntryFound = 'TRUE'
  1320.  
  1321.                 if ( Table.Freshness.CachedEntryIndex = 'STALE' ) then do
  1322.                     call DownloadNParseList
  1323.                     call RefreshCacheEntry CachedEntryIndex
  1324.                     leave   /* leave the DO Loop */
  1325.                 end
  1326.  
  1327.                 RefreshInterval = VRGetIni( "VxFTP", "RefreshInterval", IniFile, "NoClose")
  1328.                 if ( time(minutes) - Table.CreateTime.CachedEntryIndex <= RefreshInterval ) then do
  1329.                     call UseCachedDirectory
  1330.                     leave   /* leave the DO Loop */
  1331.                   end
  1332.                 else do
  1333.                     call DownloadNParseList
  1334.                     call RefreshCacheEntry CachedEntryIndex
  1335.                     leave   /* leave the DO Loop */
  1336.                 end /* else */
  1337.             end /* if */
  1338.         end /* do */
  1339.         if ( CachedEntryFound = 'FALSE' ) then do
  1340.             call DownloadNParseList
  1341.             call AddToDirCache
  1342.         end
  1343.     end /* end else */
  1344.  
  1345. return
  1346.  
  1347. /*:VRX         ResetFileList
  1348. */
  1349. ResetFileList: 
  1350.     command = "call ParseRemoteFileList"SysType
  1351.     interpret command
  1352. return
  1353.  
  1354. /*:VRX         SendQuotedMsg
  1355. */
  1356. SendQuotedMsg: 
  1357.     rc = VRMethod( "Application", "GetVar", "QuotedMsg" )
  1358.  
  1359.     TextToSend = 'call VRSet "MainWindow", "StatusText", "Sending message <<'QuotedMsg'>>"'
  1360.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1361.  
  1362.     rc = FtpQuote( QuotedMsg )
  1363.     if (FTPERRNO <> 0) then  call FTPErrMsg
  1364.  
  1365.     TextToSend = 'call VRSet "MainWindow", "StatusText", ""'
  1366.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1367.  
  1368. return
  1369.  
  1370. /*:VRX         SendSiteCmd
  1371. */
  1372. SendSiteCmd: 
  1373.     rc = VRMethod( "Application", "GetVar", "SiteCmd" )
  1374.  
  1375.     TextToSend = 'call VRSet "MainWindow", "StatusText", "Sending command <<'SiteCmd'>>"'
  1376.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1377.  
  1378.     rc = FtpSite( SiteCmd )
  1379.     if (FTPERRNO <> 0) then  call FTPErrMsg
  1380.  
  1381.     TextToSend = 'call VRSet "MainWindow", "StatusText", ""'
  1382.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1383.  
  1384. return
  1385.  
  1386. /*:VRX         SetAscii
  1387. */
  1388. SetAscii: 
  1389.     XferType = 'Ascii'
  1390. return
  1391.  
  1392. /*:VRX         SetBinary
  1393. */
  1394. SetBinary: 
  1395.     XferType = 'Binary'
  1396. return
  1397.  
  1398. /*:VRX         SetRemoteCWD
  1399. */
  1400. SetRemoteCWD:
  1401.     rc = VRMethod("Application", "PostQueue", 0, 1, "call Clear_Remote")
  1402.  
  1403.     command = "call ParseRemoteCWD_"SysType
  1404.     interpret command
  1405.  
  1406.     /* Add the "word"s within "remDirs" to RemoteCWDDirs. stem,
  1407.        replacing any astericks with the blank spaces that were
  1408.        originally there.
  1409.      */
  1410.     do i = 1 to numDirs
  1411.         RemoteCWDDirs.i = word(remDirs, numDirs-(i-1))
  1412.         RemoteCWDDirs.i = translate(RemoteCWDDirs.i, ' ', '*')
  1413.     end
  1414.  
  1415.     call VRMethod "Application", "PutVar", "RemoteCWDDirs."
  1416.     call VRMethod "Application", "PostQueue", 0, 1, "call Set_DDCB_Remote_CWD"
  1417.  
  1418.     drop remDirs numDirs
  1419. return
  1420.  
  1421. /*:VRX         SetRemotePath
  1422. */
  1423. SetRemotePath:
  1424.     rc = FtpPwd( RemotePWD )
  1425.     parse var RemotePWD '"' GRemotePath '"' rest    /* GRemotePath gets 
  1426.                                                        RemotePWD cleaned up      */
  1427.     drop RemotePWD 
  1428. return
  1429. /*:VRX         SetSysType
  1430. */
  1431. SetSysType:
  1432.     SysType = VRInfo( "systype" )
  1433.  
  1434. return
  1435.  
  1436. /*:VRX         SetupDirCacheTable
  1437. */
  1438. SetupDirCacheTable:
  1439.  
  1440.     Table.Dir_Name.0 = 0
  1441.     Table.Freshness.0 = 0
  1442.     Table.CreateTime.0 = 0
  1443.     Table.dirs.0.0 = 0
  1444.     Table.files.0.0 = 0
  1445.     Table.dates.0.0 = 0
  1446.     Table.times.0.0 = 0
  1447.     Table.sizes.0.0 = 0
  1448.     TableIndex = 0
  1449.     TableSize = 0
  1450. return
  1451.  
  1452. /*:VRX         SpawnXferProgress
  1453. */
  1454. SpawnXferProgress: procedure expose SysType XferProgTID
  1455.     parse arg getFile getFileSize remoteFile
  1456.  
  1457.     XferProgTID = VRMethod( "Application", "StartThread", "XferProg", SysType getFile getFileSize remoteFile )
  1458.  
  1459.     if ( XferProgTID = -1 ) then
  1460.         call BasicErrMsg "Couldn't start 'XferProgress' thread for" getFile
  1461. return
  1462.  
  1463. /*:VRX         syntax_handler
  1464. */
  1465. syntax_handler: 
  1466.     if ( FTPFuncsLoaded = 'NO' ) then do
  1467.         call VRMethod "Application", "PostQueue", 0, 1, ,
  1468.             "Call BasicErrMsg 'Could not load FTP functions.'"
  1469.         call VRMethod "Application", "PostQueue", 0, 1, ,
  1470.             "Call Quit"
  1471.      end
  1472.     else
  1473.         call VRMethod "Application", "PostQueue", 0, 1, ,
  1474.             "Call BasicErrMsg 'Remote Function call failed.'"
  1475.         
  1476. return
  1477.  
  1478. /*:VRX         UseCachedDirectory
  1479. */
  1480. UseCachedDirectory: 
  1481.     /* Given the index "CachedEntryIndex" into the Cache table
  1482.      * assign the Table values to the remote_* stems. Then post
  1483.      * to the GUI thread.
  1484.      */
  1485.     TextToSend = 'call VRSet "MainWindow", "StatusText", "Extracting file list from cache"'
  1486.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1487.  
  1488.     do j = 1 to Table.files.CachedEntryIndex.0
  1489.         remote_file.j = Table.files.CachedEntryIndex.j
  1490.         remote_size.j = Table.sizes.CachedEntryIndex.j
  1491.         remote_date.j = Table.dates.CachedEntryIndex.j
  1492.         remote_time.j = Table.sizes.CachedEntryIndex.j
  1493.     end
  1494.     remote_file.0 = j - 1
  1495.     remote_size.0 = j - 1
  1496.     remote_date.0 = j - 1
  1497.     remote_time.0 = j - 1
  1498.  
  1499.     do j = 1 to Table.dirs.CachedEntryIndex.0
  1500.         remote_dir.j = Table.dirs.CachedEntryIndex.j
  1501.     end
  1502.     remote_dir.0 = j - 1
  1503.  
  1504.     call PostRemoteFiles
  1505.  
  1506.     TextToSend = 'call VRSet "MainWindow", "StatusText", " "'
  1507.     rc = VRMethod( "Application", "PostQueue", 0, 1, TextToSend )
  1508.  
  1509.     drop j
  1510. return
  1511.  
  1512. /*:VRX         ViewFiles
  1513. */
  1514. ViewFiles:
  1515.     call VRMethod "Application", "GetVar", "filesToView."
  1516.     call VRMethod "Application", "GetVar", "filesToViewSize."
  1517.  
  1518.     /* Check whether or not user wants to use the E system
  1519.      * editor to view files.
  1520.      */
  1521.     EEditor = VRGetIni( "VxFTP", "EEditor", IniFile, "NoClose" )
  1522.  
  1523.     do i = 1 to filesToView.0
  1524.         if ( EEditor = 1 ) then
  1525.             localfile = filesToView.i
  1526.         else
  1527.             localfile = SysTempFileName('ViewTemp.???')
  1528.  
  1529. /*        call SpawnXferProgress localfile filesToViewSize.i
  1530.  */
  1531.         if ( SysType = "UNIX" | SysType = "VM" ) then
  1532.             rc = FtpGet( localfile, filesToView.i, "ASCII" )
  1533.         else
  1534.             rc = FtpGet( localfile, filesToView.i, "BINARY" )
  1535.         if (FTPERRNO <> 0) then call FTPErrMsg
  1536.  
  1537.         if ( EEditor = 1 ) then do
  1538.             command = 'start /f e "' || localfile || '"'
  1539.             address cmd command
  1540.         end
  1541.         else do
  1542.             /* Must indicate that we're Viewing a text from a remote site, so that
  1543.              * we can delete it once we've brought it down. (When viewing local
  1544.              * files, we don't delete the file!! )
  1545.              */
  1546.             TextFileTID = VRMethod("Application", "StartThread", "TextFile", localfile"||"filesToView.i"||REMOTE" )
  1547.             if TextFileTID = 0 then
  1548.                 call BasicErrMsg "Couldn't start View Text File thread."
  1549.         end /* else */
  1550.     end /* do */
  1551.     
  1552.     rc = VRMethod( "Application", "PostQueue", 0, 1, "call XferComplete 'NoShow'" )
  1553.  
  1554.     drop EEditor command
  1555. return
  1556.  
  1557.