home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / xbftp10.zip / ftptest.prg next >
Text File  |  1998-06-18  |  10KB  |  374 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  Purpose     : testing the OS/2 FTP-Library for XBase++
  4. //
  5. //  Version     : 1.0
  6. //
  7. //  Last Update : Thu 18.06.1998
  8. //
  9. //  File        : FtpTest.prg
  10. //
  11. //  Copyright   : homburg Softwaretechnik, (c) 1998. All rights reserved
  12. //
  13. //  Contact     : Internet : http://dienstleistungen.freepage.de/shomburg
  14. //                eMail    : shomburg@ibm.net
  15. //
  16. //  !! NOTE !!  : before compile the source, please check
  17. //                the <hostname>, <username> and <password>
  18. //                in the function "ipFtpLogin" in sourceline 73
  19. //
  20. //  !! NOTE !!  : before compile the source, please check your access
  21. //                rights on the remote machine for all path and filename
  22. //                in sourceline 135,150,168,185,199,216,251,268,285 and 286
  23. //
  24. ///////////////////////////////////////////////////////////////////////////////
  25. #include "xbftp.ch"
  26.  
  27. REQUEST ipFtpInit, ipFtpDeInit, ipFtpSys, ipFtpLogin
  28. REQUEST ipFtpLogoff, ipFtpPing, ipFtpVer, ipFtpLs
  29. REQUEST ipFtpRmd, ipFtpMkd, ipFtpCd, ipFtpDelete, ipFtpDir, ipFtpPwd
  30. REQUEST ipFtpGet, ipFtpPut, ipFtpPutUnique, ipFtpRename
  31. REQUEST ipFtpTraceOn, ipFtpTraceOff, ipFtpSite, ipFtpQuote
  32.  
  33. PROCEDURE Main()
  34.   local errorCode
  35.   local FtpHandle
  36.   local sysMessage
  37.   local verMessage
  38.   local pathMessage
  39.  
  40.   set printer to "ftptest.log"
  41.   set device to printer
  42.   set printer on
  43.  
  44.   //
  45.   // initialize the FTP-Library
  46.   //
  47.   ? ""
  48.   ? "call ipFtpInit()"
  49.   errorCode = ipFtpInit()
  50.   if (errorCode != 0)
  51.     ? "error in ipFtpInit() occured : " + alltrim(str(errorCode))
  52.     return
  53.   endif
  54.   ? "XbFtp-DLL initialized successfully"
  55.   ? "press any key ..."
  56.   inkey()
  57.  
  58.   //
  59.   // start Trace to file "trace.txt" in append mode
  60.   //
  61.   ? ""
  62.   ? "call ipFtpTraceOn()"
  63.   errorCode := ipFtpTraceOn("trace.txt",MODE_APPEND)
  64.   ? "starting trace-mode ..."
  65.   ? "press any key ..."
  66.   inkey(0)
  67.  
  68.   //
  69.   // "login" into the requested FTP-Server
  70.   //
  71.   ? ""
  72.   ? "call ipFtpLogin()"
  73.   FtpHandle = ipFtpLogin("hostname","username","password")
  74.   if (FtpHandle < 0)
  75.     ? "error in ipFtpLogin() occured : " + alltrim(str(FtpHandle))
  76.     ipFtpDeInit()
  77.     return
  78.   endif
  79.  
  80.   //
  81.   // Stores the string containing the FTP server
  82.   // description of the operating system running
  83.   // on the host in a buffer
  84.   //
  85.   ? ""
  86.   ? "call ipFtpSys()"
  87.   errorCode := ipFtpSys(FtpHandle,@sysMessage)
  88.   if (errorCode == 0)
  89.     ? ""
  90.     ? "FTP-Server returned following Message : "
  91.     ? "-> " + sysMessage
  92.     ? "press any key ..."
  93.     inkey(0)
  94.   endif
  95.  
  96.   //
  97.   // Stores the string containing the FTP API version
  98.   //
  99.   ? ""
  100.   ? "call ipFtpVer()"
  101.   errorCode := ipFtpVer(FtpHandle,@verMessage)
  102.   if (errorCode == 0)
  103.     ? ""
  104.     ? "Your System returned following Version-String : "
  105.     ? "-> " + verMessage
  106.     ? "press any key ..."
  107.     inkey(0)
  108.   endif
  109.  
  110.  
  111.   //
  112.   // Sends a ping to the remote host to determine
  113.   // if the host is responding
  114.   //
  115.   ? ""
  116.   ? "call ipFtpPing()"
  117.   errorCode := ipFtpPing(FtpHandle,256)
  118.   if (errorCode == 0)
  119.     ? ""
  120.     ? "the Ping to the FTP-Server was successfull"
  121.   else
  122.     ? ""
  123.     ? "the Ping to the FTP-Server was NOT successfull"
  124.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  125.   endif
  126.   ? "press any key ..."
  127.   inkey(0)
  128.  
  129.   //
  130.   // gets directory information in short format
  131.   // from a remote host and writes it to a local file.
  132.   //
  133.   ? ""
  134.   ? "call ipFtpLs()"
  135.   errorCode := ipFtpLs(FtpHandle,"ftpdir1.txt","*")
  136.   if (errorCode == 0)
  137.     ? "the ls at the FTP-Server was successfull"
  138.   else
  139.     ? "the ls at the FTP-Server was NOT successfull"
  140.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  141.   endif
  142.   ? "press any key ..."
  143.   inkey(0)
  144.  
  145.   //
  146.   // Changes the current working directory on a host
  147.   //
  148.   ? ""
  149.   ? "call ipFtpCd()"
  150.   errorCode := ipFtpCd(FtpHandle,"/etc")
  151.   if (errorCode == 0)
  152.     ? ""
  153.     ? "the cd at the FTP-Server was successfull"
  154.   else
  155.     ? ""
  156.     ? "the cd at the FTP-Server was NOT successfull"
  157.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  158.   endif
  159.   ? "press any key ..."
  160.   inkey(0)
  161.  
  162.   //
  163.   // Gets a directory in wide format
  164.   // from a remote host and writes it to a local file.
  165.   //
  166.   ? ""
  167.   ? "call ipFtpDir()"
  168.   errorCode := ipFtpDir(FtpHandle,"ftpdir2.txt","*")
  169.   if (errorCode == 0)
  170.     ? ""
  171.     ? "the dir at the FTP-Server was successfull"
  172.   else
  173.     ? ""
  174.     ? "the dir at the FTP-Server was NOT successfull"
  175.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  176.   endif
  177.   ? "press any key ..."
  178.   inkey(0)
  179.  
  180.   //
  181.   // Transfers a file to an FTP server
  182.   //
  183.   ? ""
  184.   ? "call ipFtpPut()"
  185.   errorCode := ipFtpPut(FtpHandle,"xbftp.ch","/usr/tmp/xbftp.test")
  186.   if (errorCode == 0)
  187.     ? ""
  188.     ? "the file-transfer to the FTP-Server was successfull"
  189.   else
  190.     ? ""
  191.     ? "the file-transfer to the FTP-Server was NOT successfull"
  192.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  193.   endif
  194.   ? "press any key ..."
  195.   inkey(0)
  196.  
  197.   ? ""
  198.   ? "call ipFtpPutUnique()"
  199.   errorCode := ipFtpPutUnique(FtpHandle,"xbftp.ch","/usr/tmp/xbftp.test")
  200.   if (errorCode == 0)
  201.     ? ""
  202.     ? "the unique-file-transfer to the FTP-Server was successfull"
  203.   else
  204.     ? ""
  205.     ? "the unique-file-transfer to the FTP-Server was NOT successfull"
  206.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  207.   endif
  208.   ? "press any key ..."
  209.   inkey(0)
  210.  
  211.   //
  212.   // appends information to a remote file.
  213.   //
  214.   ? ""
  215.   ? "call ipFtpAppend()"
  216.   errorCode := ipFtpAppend(FtpHandle,"c:/autoexec.bat","/usr/tmp/xbftp.test")
  217.   if (errorCode == 0)
  218.     ? ""
  219.     ? "the file-append to the FTP-Server was successfull"
  220.   else
  221.     ? ""
  222.     ? "the file-append to the FTP-Server was NOT successfull"
  223.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  224.   endif
  225.   ? "press any key ..."
  226.   inkey(0)
  227.  
  228.   //
  229.   // returns the actual Path on remote host
  230.   //
  231.   ? ""
  232.   ? "call ipFtpPwd()"
  233.   errorCode := ipFtpPwd(FtpHandle,@pathMessage)
  234.   if (errorCode == 0)
  235.     ? ""
  236.     ? "the pwd-command at the FTP-Server was successfull"
  237.     ? "the actual path is : " + pathMessage
  238.   else
  239.     ? ""
  240.     ? "the file-delete at the FTP-Server was NOT successfull"
  241.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  242.   endif
  243.   ? "press any key ..."
  244.   inkey(0)
  245.  
  246.   //
  247.   // gets a file from the remote host
  248.   //
  249.   ? ""
  250.   ? "call ipFtpGet()"
  251.   errorCode := ipFtpGet(FtpHandle,"ftpget.test","/usr/tmp/xbftp.test","w")
  252.   if (errorCode == 0)
  253.     ? ""
  254.     ? "the file-transfer from the FTP-Server was successfull"
  255.   else
  256.     ? ""
  257.     ? "the file-transfer from the FTP-Server was NOT successfull"
  258.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  259.   endif
  260.   ? "press any key ..."
  261.   inkey(0)
  262.  
  263.   //
  264.   // Renames a file on a remote host
  265.   //
  266.   ? ""
  267.   ? "call ipFtpRename()"
  268.   errorCode := ipFtpRename(FtpHandle,"/usr/tmp/xbftp.test","/usr/tmp/xbftp.test.xxx")
  269.   if (errorCode == 0)
  270.     ? ""
  271.     ? "the file-rename at the FTP-Server was successfull"
  272.   else
  273.     ? ""
  274.     ? "the file-rename at the FTP-Server was NOT successfull"
  275.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  276.   endif
  277.   ? "press any key ..."
  278.   inkey(0)
  279.  
  280.   //
  281.   // Deletes files on a remote host
  282.   //
  283.   ? ""
  284.   ? "call ipFtpDelete()"
  285.   errorCode := ipFtpDelete(FtpHandle,"/usr/tmp/xbftp.test.xxx")
  286.   errorCode := ipFtpDelete(FtpHandle,"/usr/tmp/xbftp.test.1")
  287.   if (errorCode == 0)
  288.     ? ""
  289.     ? "the file-delete at the FTP-Server was successfull"
  290.   else
  291.     ? ""
  292.     ? "the file-delete at the FTP-Server was NOT successfull"
  293.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  294.   endif
  295.   ? "press any key ..."
  296.   inkey(0)
  297.  
  298.   //
  299.   // Executes the SITE command
  300.   //
  301.   ? ""
  302.   ? "call ipFtpSite()"
  303.   errorCode := ipFtpSite(FtpHandle,"idle 2000")
  304.   if (errorCode == 0)
  305.     ? ""
  306.     ? "the sitecommand at the FTP-Server was successfull"
  307.   else
  308.     ? ""
  309.     ? "the sitecommand at the FTP-Server was NOT successfull"
  310.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  311.   endif
  312.   ? "press any key ..."
  313.   inkey(0)
  314.  
  315.   //
  316.   // Executes the QUOTE command
  317.   //
  318.   ? ""
  319.   ? "call ipFtpQuote()"
  320.   errorCode := ipFtpQuote(FtpHandle,"site idle 1500")
  321.   if (errorCode == 0)
  322.     ? ""
  323.     ? "the quotecommand at the FTP-Server was successfull"
  324.   else
  325.     ? ""
  326.     ? "the quotecommand at the FTP-Server was NOT successfull"
  327.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  328.   endif
  329.   ? "press any key ..."
  330.   inkey(0)
  331.  
  332.   //
  333.   // Closes the current connections
  334.   //
  335.   ? ""
  336.   ? "call ipFtpLogoff()"
  337.   errorCode = ipFtpLogoff(FtpHandle)
  338.   if (errorCode == 0)
  339.     ? ""
  340.     ? "the logoff  was successfull"
  341.   else
  342.     ? ""
  343.     ? "the logoff was NOT successfull"
  344.     ? "and returned with errorcode : " + Alltrim(str(errorCode))
  345.   endif
  346.   ? "press any key ..."
  347.   inkey(0)
  348.  
  349.   //
  350.   // Closes the trace file, and stops tracing of
  351.   // the command and reply sequences that were
  352.   // sent over the control connection between the
  353.   // local and remote hosts
  354.   //
  355.   ? ""
  356.   ? "call ipFtpTraceOff()"
  357.   ipFtpTraceOff()
  358.  
  359.   //
  360.   // Closes all current connections and deinit the library
  361.   //
  362.   ? ""
  363.   ? "call ipFtpDeInit()"
  364.   ipFtpDeInit()
  365.  
  366.   ? ""
  367.   ? "ready with demo"
  368.   ? "press any key to exit"
  369.   inkey(0)
  370.  
  371.   return
  372.  
  373.  
  374.