FTP Server>FTP Server programming
Introduction Installation Beginning Admin Quick Ref FTP Server SMTP Server Database Security
Statements Objects String Parsing Events Queues Samples Special names Error Handling Accessories   Back
Caravan Business Server>Help>FTP Server>FTP Server programming
Syntax
Text
The Caravan FTP server is now an integral part of the application platform, so the developer
can now integrate the ftp services directly to the application context. Previously the Caravan
ftp server was just like any other ftp server -- it just served static files from the user's
ftphome directory. Now for the first time Caravan ftp server can actually serve dynamic content
generated by the application logic!

The ftp server's access control is managed by Caravan's user management system. Ftp access for the
user is granted as per the ftphome property of the user. For static ftp , this value is the users's
home directory for ftp operations. With  versions> 3.00  this value can also be the name of a
caravan script which is the code written specifically to service the ftp requests from this user.
Caravan will redirect all ftp commands from the client to this code.

The script which is intented for ftp servicing , is executed by caravan everytime the ftp client
sends a command. Ftp commands are passed in the 'form(command)' property. The code should process
the following commands . If the processing was successfull ftp(ok) should be setto "yes";

These are the command strings and their purpose is given below:

"user"; client logged in; just for information ; form(param) giver user's login
        -- should ok by setting the ftp(ok) property.

"list"; list filenames with time and size and type; form(arg) gives file specification if any.

"nlst"; list filenames only ; form(arg) gives file specification (is *.zip etc) if any

"retr"; client wants to get a file whose name is form(arg)
"retrd"; get command on form(arg) was successfull

"stor"; client wants to put a file which is the value of form(param)

"rmd"; client wants to delete a  directory whose name is given in form(arg)

"ren";  client wants to rename file from form(param) to form(arg)

"mkd"; client wants makes a new directory of name 'form(arg)'

"dele"; client wants to delete a file whose name is given in 'form(arg)'

"cwd"; client wants to change directory to form(arg);

"quit"; the client has logged out


An object of name 'ftp' is passed to the the script. The 'ok' property should be set if
the command was successfull. The 'ftp' object will hold the result of the precessing like
file list, file content etc.

An object of name 'form' is also passed to the script which contains all the information
about the command.

'form' has following properties :

command : One of the command tokens listed above -- which commands to process and which to ignore
            is upto the programmer. Minimum "list","nlst" and "retr" will need to implemented.

pwd : present working directory of the client -- can give the context of users' actions
      this will be something like 'users/kdv/files'

arg : first argument to the command -- most commands have an argument

param: second argument of the command -- some commands need 2 arguments . This value
also holds the entire file in "stor" (put) command .

It is also possible to maintain additional persistent objects for the duration of the user's
ftp session.
Sample
//Sample code for servicing ftp requests:
<caravan>
  // output the input params to console
  "command=";form(command);"\r\n" ; // the command to be serviced
  "arg=";form(arg);"\r\n";// first argument if any
  "param=";form(param);"\r\n";// second  argument if any
  "user=";userinfo(username);"\r\n";// userinfo object gives the logged in users's info
  "domain=";userinfo(domain);"\r\n";// domain can also be used
  "pwd=";form(pwd);"\r\n";// present working directory
  "session=";session(name);"\r\n" ;// persistent object
  "==========================\r\n"
// for each command there should be code which

if form(command)="list"
  folder x="c:\ftp\test"; // we are simply serving from a folder but it could be from database if needed
  if form(arg)
   x(filespec)=FORM(arg)
  else
   x(filespec)="*.cpp"
  endif
  loop xl (500)
   if x(filename)
    ftp(filename)=x(filename);// we fill in the filenames in the object 'ftp'
    ftp(time)=x(time);// size and time are needed for 'list'
    ftp(size)=x(size)
    x(findnext)
   else
     break
   endif
  repeat xl 500
  ftp(ok)="1";// command was successfull ; if this is not set client will get "500 command failed"
elseif form(command)="nlst"
      folder x="c:\kdv\new"
      if form(arg)
       x(filespec)=FORM(arg);// List only the files which the user has requested
      else
       x(filespec)="*.cpp"
      endif
      loop xl (500)
      if x(filename)
         ftp(filename)=x(filename)
         x(findnext)
        else
         break
        endif
        repeat xl 500
        ftp(ok)="1"
elseif form(command)="retr"
      if form(arg)
        folder x="c:\kdv\new"
        x(filename)=form(arg)
        if x(filename)=form(arg)
         ftp(file)=x(file)
         ftp(ok)="1"
        endif
      endif
elseif form(command)="user"
       var session;// example creating a persistent object which will now be available for the duration of the session
       session(persistent)="yes"
       session(name)=userinfo(domain)
       ftp(ok)="1"
       "Ftp login from ";userinfo(username);"\r\n"
elseif form(command)="cwd"
       ftp(ok)="yes";//
       "change directory to ";form(arg);"\r\n"
elseif form(command)="stor"
         ftp(ok)="yes"
         file x=form(param);// this is the file put by the user
         x(file);// we dump it on console
endif
</caravan>
Quick Reference
Home       Back