home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / MODEM / HOST1.ZIP / HOSTFILE.SCR < prev    next >
Text File  |  1994-02-20  |  6KB  |  215 lines

  1. ' File area routines for host mode.
  2.  
  3. function GetProtocol as integer
  4.   dim s as string
  5.   if not DisplayFile(ProtocolFileName) then
  6.     send #Port, "Select a file transfer protocol:"
  7.     send #Port,
  8.     send #Port, "[A] Ascii  [X] Xmodem   [C] Xmodem/CRC  [1] Xmodem/1K  [F] Xmodem/1KG"
  9.     send #Port, "[Y] Ymodem [G] Ymodem/G [Z] Zmodem      [K] Kermit"
  10.   end if
  11.   send #Port,
  12.   send #Port, "Current directory is:"
  13.   send #Port, curdir
  14.   s = GetLine("Protocol: ")
  15.   select case OemUpper(left(s, 1))
  16.     case "A"
  17.       GetProtocol = ASCII
  18.     case "X"
  19.       GetProtocol = Xmodem
  20.     case "C"
  21.       GetProtocol = XmodemCRC
  22.     case "1"
  23.       GetProtocol = Xmodem1K
  24.     case "F"
  25.       GetProtocol = Xmodem1KG
  26.     case "Y"
  27.       GetProtocol = Ymodem
  28.     case "G"
  29.       GetProtocol = YmodemG
  30.     case "Z"
  31.       GetProtocol = Zmodem
  32.     case "K"
  33.       GetProtocol = Kermit
  34.   end select
  35. end function
  36.  
  37. function ProtocolName(prot as integer) as string
  38.   select case prot
  39.     case ASCII
  40.       ProtocolName = "ASCII"
  41.     case Xmodem
  42.       ProtocolName = "Xmodem"
  43.     case XmodemCRC
  44.       ProtocolName = "Xmodem/CRC"
  45.     case Xmodem1K
  46.       ProtocolName = "Xmodem/1K"
  47.     case Xmodem1KG
  48.       ProtocolName = "Xmodem/1KG"
  49.     case Ymodem
  50.       ProtocolName = "Ymodem"
  51.     case YmodemG
  52.       ProtocolName = "Ymodem/G"
  53.     case Zmodem
  54.       ProtocolName = "Zmodem"
  55.     case Kermit
  56.       ProtocolName = "Kermit"
  57.   end select
  58. end function
  59.  
  60. ' List files
  61.  
  62. sub ListFiles
  63.   dim result as integer, count as integer, total as integer, sr as SearchRec
  64.   if Setup.dlpath = "" then
  65.     send #Port,
  66.     send #Port, "Sorry, downloads are not available."
  67.     send #Port,
  68.     exit sub
  69.   end if
  70.   total = 0
  71.   count = 0
  72.   result = FindFirst(AddBackSlash(curdir)+"*.*", 0, sr)
  73.   do while result = 0 and not CallerHungUp
  74.     dim i as integer
  75.     i = instr(sr.name, ".")
  76.     if i > 0 then
  77.       send #Port, left(sr.name, i-1); tab(10); right(sr.name, len(sr.name)-i); tab(14);
  78.     else
  79.       send #Port, sr.name; tab(14);
  80.     end if
  81.     send #Port, space(11-len(str(sr.size))); sr.size;
  82.     send #Port, DateToDateString(" mm-dd-yy", DMYtoDate(sr.date and 0x1f, (sr.date\32) and 0xf, 1980+(sr.date\512)));
  83.     send #Port, TimeToTimeString(" HH:mmt", HMStoTime(sr.time\2048, (sr.time\32) and 0x3f, (sr.time and 0x1f) * 2));
  84.     send #Port,
  85.     total = total + 1
  86.     count = count + 1
  87.     if count >= 24 then
  88.       if OemUpper(GetLine("-Pause- [C]ontinue, [S]top? ", 1)) = "S" then
  89.         exit do
  90.       end if
  91.       count = 0
  92.     end if
  93.     result = FindNext(sr)
  94.   loop
  95.   send #Port,
  96.   send #Port, total; " file(s) available in"
  97.   send #Port, curdir
  98.   send #Port,
  99.   GetLine "Press Enter to continue? "
  100. end sub
  101.  
  102. ' Download file
  103.  
  104. sub DownloadFile
  105.   dim fnames as string, protocol as integer, count as integer
  106.   dim onefile as integer
  107.   if Setup.dlpath = "" then
  108.     send #Port,
  109.     send #Port, "Sorry, downloads are not available."
  110.     send #Port,
  111.     exit sub
  112.   end if
  113.   protocol = GetProtocol()
  114.   if protocol = 0 then exit sub
  115.   onefile = protocol < Ymodem
  116.   do
  117.     dim s as string
  118.     s = GetLine("File to download: ")
  119.     if CallerHungUp then
  120.       exit sub
  121.     end if
  122.     if s = "" then exit do
  123.     send #Port,
  124.     if not Setup.sysopanypath = 0 or User.Level = 0 then
  125.       s = AddBackSlash(curdir)+JustFilename(s)
  126.     elseif instr(s, "\") = 0 then
  127.       s = AddBackSlash(curdir)+JustFilename(s)
  128.     end if
  129.     dim sr as SearchRec
  130.     if findfirst(s, 0, sr) = 0 then
  131.       do
  132.         if len(fnames) > 0 then
  133.           fnames = fnames + " "
  134.         end if
  135.         fnames = fnames + AddBackSlash(JustPathName(s)) + sr.Name
  136.         count = count + 1
  137.         dim i as integer
  138.         i = instr(sr.name, ".")
  139.         if i > 0 then
  140.           send #Port, left(sr.name, i-1); tab(10); right(sr.name, len(sr.name)-i); tab(14);
  141.         else
  142.           send #Port, sr.name; tab(14);
  143.         end if
  144.         send #Port, space(11-len(str(sr.size))); sr.size;
  145.         send #Port, DateToDateString(" mm-dd-yy", DMYtoDate(sr.date and 0x1f, (sr.date\32) and 0xf, 1980+(sr.date\512)));
  146.         send #Port, TimeToTimeString(" HH:mmt", HMStoTime(sr.time\2048, (sr.time\32) and 0x3f, (sr.time and 0x1f) * 2));
  147.         send #Port,
  148.       loop until (onefile and count = 1) or findnext(sr) <> 0
  149.       send #Port,
  150.     else
  151.       send #Port, "The file "; s; " could not be found on disk."
  152.     end if
  153.   loop until onefile and count = 1
  154.   if count > 0 then
  155.     if Local then
  156.       send #Port, "The following files would be transferred if you were not on locally:"
  157.       send #Port, fnames
  158.     else
  159.       send #Port,
  160.       send #Port, "Begin your "; ProtocolName(protocol); " download of ";
  161.       if count = 1 then
  162.         send #Port, fnames;
  163.       else
  164.         send #Port, count, " files"
  165.       end if
  166.       send #Port, " now"
  167.       delay 1
  168.       sendfile fnames, protocol
  169.     end if
  170.   else
  171.     send #Port, "No files selected."
  172.   end if
  173. end sub
  174.  
  175. ' Upload file
  176.  
  177. sub UploadFile
  178.   dim fname as string, protocol as integer, sysopupdir as string
  179.   sysopupdir = setup.ulpath
  180.   if Setup.ulpath = "" then
  181.     send #Port,
  182.     send #Port, "Sorry, uploads are not available."
  183.     send #Port,
  184.     exit sub
  185.   end if
  186.   if Local then
  187.     send #Port, "Uploads not available when logged on locally"
  188.     exit sub
  189.   end if
  190.   protocol = GetProtocol()
  191.   send #Port,
  192.   send #Port, "File(s) will be uploaded to"
  193.   send #Port, sysopupdir
  194.   if protocol = 0 or CallerHungUp then exit sub
  195.   send #Port,
  196.   fname = "your file"
  197.   if protocol < Ymodem then
  198.     fname = GetLine("File to upload: ")
  199.     send #Port,
  200.     if fname = "" or CallerHungUp then exit sub
  201.     fname = AddBackSlash(Setup.ulpath)+JustFilename(fname)
  202.     if exists(fname) then
  203.       send #Port, "The file "; fname; " already exists on disk."
  204.       exit sub
  205.     end if
  206.   else
  207.     fname = Setup.ulpath
  208.   end if
  209.   send #Port, "Begin your "; ProtocolName(protocol); " upload of "; fname; " now"
  210.   delay 1
  211.   receivefile fname, protocol
  212. end sub
  213.  
  214.  
  215.