Lightweight, Component-based, and Database-oriented Web Application Framework

About | Overview | Documentation


Documentation > Modules and APIs > FTP_Service




The core module that acts as wrapper for functions offered by CPAN's Net::FTP module. It's intensively used inside the webman_FTP_upload component-type module to support the implementation of file upload operation/maintenance from client browser to application server host.



CPAN's Modules:

  • Net::FTP (Composition)


1. Instantiation and Basic Parameter Setting

The $cgi is an instance of GMM_CGI core module used by FTP_Service instance ($ftp_srvc) to retrieve CGI parameters which related with file upload operation/maintenance.

my $ftp_srvc = new FTP_Service;


$ftp_srvc->set_FTP_Conn($host, $login, $password);

2. File Upload Operation

File upload operation normally requires the module to be composed together with other component-type module. The Webman-framework composes FTP_Service core module inside webman_FTP_upload component-type module. The main role of component-type module is to provide the mechanism to upload and save client's files into the temporary directory ($dir_temp) before they are copied/saved into the target upload directory ($dir_upload).



The $file_name_list is a reference of array that store the names of files being uploaded. It can be supplied by the component-type module that used to handle the task to save the uploaded files into the temporary directory. If omitted, the FTP_Service module can automatically get the uploaded file name list directly from the $cgi instance as set previously in section 1. The returned $file_info is a reference of array of hash reference of details information of the uploaded files. It's items are hash references with keys ("dir_upload", "name", "ext", "status", and "save_mode") to represent the file information data.

my $file_name_list = ...;

my $file_info = $ftp_srvc->generate_File_Info($file_name_list);

Modifications of $file_info array reference item's keys as hash references outside the implementation of $ftp_srvc instance functions will also affect the way of how the $ftp_srvc instance will react on the save operation. For example, if the file information key "status" is detected as "Exist", the developers have the option to prevent it from being saved by setting the "save_mode" key to "0".

### Example of code to modify files information keys/values before 

### save the files  into the upload directory.

foreach my $file (@{$file_info}) {

    if ($file->{"status"} eq "Exist") {

        $file->{save_mode} = 0;



The $file_info_saved is a reference of array of hash reference like the $file_info above, returned just after the file save operation is completed. However, its item number might be less than $file_info since developers might prevent certain files from being saved as previously demonstrated.

### Saved uploaded files into upload directory using FTP service.

my $file_info_saved = $ftp_srvc->save_Files;

### Close ftp connection.