Go to the first, previous, next, last section, table of contents.


The Ftp module

type control_connection

val set_timeout : float -> unit

sets the timeout time for all subsequent commands

type connect_args =
  Port of int
| User of string
| Password of string
  

val connect : string -> connect_args list -> control_connection

connect host args opens a connection to the host and returns a control connection. port, user and password can be specified in args.

val quit : control_connection -> unit

to close a connection, sends QUIT to the ftp server and closes the connection

val cd : control_connection -> string -> unit

cd conn path changes directory on the ftp server

val rm : control_connection -> string -> unit

rm conn file deletes the file file on the ftp server

val size : control_connection -> string -> int

size conn file returns the size of the remote file.

type get_args =
  Passive
  

val get : control_connection -> string -> Bufrw.read_buffer_type -> 
  get_args list -> float

get conn file my_read_buffer args retrieves the remote file and applies to each buffered read the function my_read_buffer. If Passive is in args, the client connects to the server, otherwise the server connects to the client. The return value is the time in seconds it took to download the file.

For instance, to save the file to local_file, do:


let out = open_out_bin local_file in
let time = get conn file (output_string out) [] in
close_out out
type put_args =
  PassivePut
  

val put : control_connection -> Bufrw.fill_buffer_type -> string -> 
  put_args list -> float

put conn my_fill_buffer file passive uploads the data provided by my_fill_buffer to the ftp server as remote file file. If passive is true, the client connects to the server, otherwise the server connects to the client. The return value is the time in seconds it took to upload the file.

For instance, to upload some file named local_file (after checking that it is a correct type of file), do:


let file_stats = Unix.stat file in
if ( file_stats.Unix.st_kind = Unix.S_REG 
or 
file_stats.Unix.st_kind = Unix.S_LNK )
then
let descr = open_in_bin file in
let time = put conn (Bufrw.fill_buffer_from_file_descr descr) remote_name [] in
close_in descr
module
 type SysCalls = sig
    val open_connection : Unix.sockaddr -> in_channel * out_channel
    val connect :  Unix.file_descr -> Unix.sockaddr -> unit
    val listen : Unix.file_descr -> int -> unit
    val bind : Unix.file_descr -> Unix.sockaddr -> unit
    val accept : Unix.file_descr -> Unix.file_descr * Unix.sockaddr
    val getsockname :  Unix.file_descr -> Unix.sockaddr
    val setsockopt : Unix.file_descr -> Unix.socket_option -> bool -> unit
    val socket :  Unix.socket_domain -> Unix.socket_type -> int -> Unix.file_descr
    val close : Unix.file_descr -> unit
  end
  
module Make: functor(SysCalls: SysCalls) -> sig
    
    val set_timeout : float -> unit
    val connect : string -> connect_args list -> control_connection
    val quit : control_connection -> unit
    val cd : control_connection -> string -> unit
    val rm : control_connection -> string -> unit
    val size : control_connection -> string -> int
    val get : control_connection -> string -> Bufrw.read_buffer_type -> 
      get_args list -> float
    val put : control_connection -> Bufrw.fill_buffer_type -> string -> 
      put_args list -> float      
  end

The Make functor can be used to create a Ftp module, whose system calls on sockets can be overriden (except read/write).


Go to the first, previous, next, last section, table of contents.