Sunday, October 23, 2011

FTP Server setup on Ubuntu.

          VSFTPD is a FTP deamon available in Ubuntu and it is easy to install, setup and maintain.

Steps :

1. Install vsftpd from Ubuntu repositories by typing the following command in a terminal Window.
sudo apt-get install vsftpd

2. During installation, user ftp will get generated with default ftp directory as "/home/ftp". If you like to change the same to another directory, then type,

"sudo usermod -d /srv/ftp ftp" 

where /srv/ftp is the new ftp directory and ftp stands for username.

3.You can restart the ftp server by typing the following command,

"/etc/init.d/vsftpd restart".

Configuration :

The default configuration file for vsftpd is /etc/vsftpd.conf. We can configure the vsftod ftp server by editing this file, as per our requirement.

1. To enable local users to login and upload files, edit the vsftpd.conf file as,
 2. To enable anonymous user to upload files, use
3. To restrict users only to their home directory, use
To include a list of users to be able to access their home directories, use
where vsftpd.chroot_list is a file includes list of users (one per line).

4. Restart vsftpd, /etc/init.d/vsftpd restart

Access :

Using a browser type "ftp://ip_address_of_server/". This will prompt for username and Password. On successful login, you can view files that are related to your user account.

Note : 
1. You can also view files remotely, under file-browser, like nautilus, etc.
2. The FTP server is not encrypted and is unsafe to use unless made secured by using  SSL (secure socket layer).

Friday, October 7, 2011

Installation of Spreadsheet::WriteExcel module for Perl

    Spreadsheet::WriteExcel module can be used to write/edit excel files. The installation procedure for this module is as given below.

1. Download

2. Unzip the module as follows, tar -zxvf Spreadsheet-WriteExcel-2.xx.tar.gz.
3. The module can be installed using the standard Perl procedure:
          perl Makefile.PL
        make test
        make install
    # You may need to be root
         make clean      # or make realclean

That's all !!!!!. Now you can write Perl programs to edit an Excel.

Sample program :

    #!/usr/bin/perl -w
    use strict;
    use Spreadsheet::WriteExcel;
    # Create a new Excel workbook
    my $workbook = Spreadsheet::WriteExcel->new("regions.xls");
    # Add some worksheets
    my $north = $workbook->addworksheet("North");
    my $south = $workbook->addworksheet("South");
    my $east  = $workbook->addworksheet("East");
    my $west  = $workbook->addworksheet("West");
    # Add a caption to each worksheet
    foreach my $worksheet (@{$workbook->{worksheets}}) {
       $worksheet->write(0, 0, "Sales");

        # Write some data
    $north->write(0, 1, 200000);
    $south->write(0, 1, 100000);
    $east->write (0, 1, 150000);
    $west->write (0, 1, 100000);
    # Set the active worksheet

Tuesday, October 4, 2011

Parse EXCEL tools under Perl.

This is a sample Perl Program to parse/read excel.

#!/usr/bin/perl -w

use strict;
use Spreadsheet::ParseExcel;

my $oExcel = new Spreadsheet::ParseExcel;

die "You must provide a filename to $0 to be parsed as an Excel file" unless @ARGV;

my $oBook = $oExcel->Parse($ARGV[0]);
my($iR, $iC, $oWkS, $oWkC);
print "FILE  :", $oBook->{File} , "\n";
print "COUNT :", $oBook->{SheetCount} , "\n";

print "AUTHOR:", $oBook->{Author} , "\n"
 if defined $oBook->{Author};

for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++)
 $oWkS = $oBook->{Worksheet}[$iSheet];
 print "--------- SHEET:", $oWkS->{Name}, "\n";
 for(my $iR = $oWkS->{MinRow} ;
     defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ;
  for(my $iC = $oWkS->{MinCol} ;
      defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol} ;
   $oWkC = $oWkS->{Cells}[$iR][$iC];
   print "( $iR , $iC ) =>", $oWkC->Value, "\n" if($oWkC);

Usage : Type "Path_to_perlfile Excel_filename_that_need_to_be_parsed.xls", in terminal window to read and display contents of an excel file.

Before that you need to ensure that the supporting modules are installed already. Under Ubuntu, the modules can be installed using command "sudo apt-get install libspreadsheet-parseexcel-perl" OR you can download the sources and copy the same to standard location of perl.