Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I wondering is it possible to make script for creating ftp accounts in perl?

I have Unix server.

share|improve this question

migrated from stackoverflow.com Mar 17 '11 at 6:19

This question came from our site for professional and enthusiast programmers.

    
If you can do it on the command line, you can do it in perl (or shell, or python, or C, or...). It depends on your ftp server. –  Mat Mar 16 '11 at 21:25
    
What version of "Unix". How do you create accounts manually (command line, web interface?). What software and versions is your FTP server? –  Cfreak Mar 16 '11 at 21:27
    
Sorry, i'm new in unix and i never tried to do such thinks. –  Mirgorod Mar 16 '11 at 21:36

1 Answer 1

I made a module to manage vsftpd accounts a few years ago from perl script. Maybe should I upload it to CPAN. Here's the test file that gives an idea how to use it :

#!/usr/bin/perl


use strict;
use warnings;

#  test script for ftpuser.pm

use Test::More 'no_plan';
# use Test::Exception;
# if Test::Exception not available
sub dies_ok(&$) {
my $coderef = shift;
my $message = shift;

eval $coderef;

ok( $@, $message)
}

# sub not_ok
sub not_ok(&$) {
my $coderef = shift;
my $message = shift;

eval $coderef;

ok( $@, $message)
}

###


# module to test
use ftpuser;

###########################
# tests OK
# open user database
ok( my $userdb = ftpuser->open_db(), "opening user base");

# open another one
ok( my $userdb2 = ftpuser->open_db('virtual_users_login.db'), "opening user base 2");

# close db
ok( $userdb->close_db(), "closing database" );

# add a user
ok($userdb2->add(user => 'user1'), "add user");

# add user with group
ok($userdb2->add(user => 'user2', group => 'geftp' ), "add user with group");


# ajouter un utilisateur (password fourni)
ok($userdb2->add(user => 'user3', password => 'testpass'), "ajout utilisateur 3");

# add user with group and password
ok($userdb2->add(user => 'user4',group => 'geftp', password => 'testpass2'), "add user with group and password");

# delete users
for my $i ( 1..4) {
        ok($userdb2->remove("user$i"), "deleting user $i");
}

###########################
# tests NOT OK

# add a user without name
dies_ok( sub{$userdb2->add(user => '')}, "add user");

# add an existing user
dies_ok(  sub{$userdb2->add(user => 'user2')}, "user already exists");

# delete a non existing user
dies_ok(  sub{$userdb2->remove(user => 'user1')}, "delete non existing user");
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.