home *** CD-ROM | disk | FTP | other *** search
/ DarkBasic Professional / DarkBasicPro.iso / data1.cab / Lang_Files_(English) / Help / examples / ftp / ftp2-example.dba < prev   
Encoding:
Text File  |  2004-09-22  |  2.9 KB  |  130 lines

  1. rem Ftp Functionality
  2. sync on
  3.  
  4. rem Run ftp tests
  5. gosub _connect : gosub _waitkey
  6. gosub _viewfiles : gosub _waitkey
  7. gosub _downloadfiles : gosub _waitkey
  8. gosub _downloadlargefile : gosub _waitkey
  9. gosub _disconnect : gosub _waitkey
  10. gosub _uploadfiles : gosub _waitkey
  11.  
  12. rem End program
  13. end
  14.  
  15. _connect:
  16.  cls : print "FTP CONNECTION"
  17.  url$="www.darkbasic.com"
  18.  user$="anonymous"
  19.  pass$="me@isp.com"
  20.  time#=timer()
  21.  print "Connecting..." : sync
  22.  ftp connect url$,user$,pass$
  23.  if get ftp failure()=0
  24.   time#=timer()-time#
  25.   print "Connection established in ";time#/1000.0;" seconds."
  26.  else
  27.   print "Could not connect to ";url$
  28.   print "Error:";get ftp error$()
  29.   wait key
  30.   end
  31.  endif
  32. return
  33.  
  34. _viewfiles:
  35.  cls : print "VIEW EACH FTP FILE IN A FOLDER"
  36.  if get ftp status()=1
  37.   print "FTP DIR:";get ftp dir$();"..." : sync
  38.   ftp find first
  39.   while get ftp file type()<>-1
  40.    print "Type:";get ftp file type();
  41.    print " Name:";get ftp file name$();
  42.    print " Size:";get ftp file size()
  43.    ftp find next
  44.    sync
  45.   endwhile
  46.  endif
  47. return
  48.  
  49. _downloadfiles:
  50.  cls : print "DOWNLOAD FTP FILES"
  51.  if get ftp status()=1
  52.   print "Getting photos\db_photo_pack1.zip..." : sync
  53.   ftp set dir "photos"
  54.   ftp get file "db_photo_pack1.zip","photos.zip"
  55.   if get ftp failure()=0
  56.    print "FTP GET FILE Succeeded!"
  57.   else
  58.    print "FTP GET FILE Failed!"
  59.   endif
  60.   ftp set dir ".."
  61.  endif
  62. return
  63.  
  64. _downloadlargefile:
  65.  cls : print "DOWNLOAD LARGE FTP FILE"
  66.  if get ftp status()=1
  67.   print "Getting photos\db_photo_pack1.zip in bits..." : sync
  68.   GrabInBits=1024
  69.   ftp set dir "photos"
  70.   ftp get file "db_photo_pack1.zip","photos.zip",GrabInBits
  71.   if get ftp failure()=0
  72.    while get ftp progress()<>-1
  73.     cls : print "DOWNLOAD LARGE FTP FILE"
  74.     print "PROGRESS:";get ftp progress()
  75.     ftp proceed
  76.    endwhile
  77.   else
  78.    print "FTP GET FILE (with progress) Failed!"
  79.   endif
  80.   ftp set dir ".."
  81.  endif
  82. return
  83.  
  84. _disconnect:
  85.  cls : print "DISCONNECTED FROM SERVER" : sync
  86.  ftp terminate
  87.  ftp disconnect
  88. return
  89.  
  90. _uploadfiles:
  91.  cls : print "UPLOAD AND DELETE FTP FILES (Your Own Server Only)"
  92.  print
  93.  input "Enter Your Own URL>";url$
  94.  input "Enter Username>";user$
  95.  input "Enter Password>";pass$
  96.  ftp connect url$,user$,pass$
  97.  if get ftp failure()=0
  98.   time#=timer()-time#
  99.   print "Connection established!"
  100.  else
  101.   print "Could not connect to ";url$
  102.   print "Error:";get ftp error$()
  103.   wait key
  104.   end
  105.  endif
  106.  if get ftp failure()=0
  107.   gosub _viewfiles
  108.   print
  109.   print "Putting file.dat..." : sync
  110.   ftp put file "file.dat"
  111.   if get ftp failure()=0
  112.    print "FTP PUT FILE Succeeded!"
  113.   else
  114.    print "FTP PUT FILE Failed!"
  115.   endif
  116.   ftp delete file "file.dat"
  117.   if get ftp failure()=0
  118.    print "FTP DELETE FILE Succeeded!"
  119.   else
  120.    print "FTP DELETE FILE Failed!"
  121.   endif
  122.  endif
  123.  ftp disconnect 1
  124. return
  125.  
  126. _waitkey:
  127.  print : print "Press Key"
  128.  wait key : sleep 500
  129. return
  130.