Use programs (Asp, Asp.net, and other languages that can access the database) to automatically create an FTP account (ODBC settings for Serv-U)

Source: Internet
Author: User

For more information, see: http://asp2004.net/dvbbs/dispbbs.asp? Boolean id = 6 & id = 287
Database script:
/***** Object: Database Host script Date: 13:16:31 ******/
If exists (Select name from Master. DBO. sysdatabases where name = n 'host ')
Drop database [host]
Go

Create Database [host] On (name = n'host _ data', filename = n'd:/wwwroot/host/database/host. MDF ', size = 2, filegrowth = 10%) log on (name = n'host _ log', filename = n'd:/wwwroot/host/database/host_log.ldf ', size = 9, filegrowth = 10%)
Collate chinese_prc_ci_as
Go

Exec sp_dboption n 'host', N 'autoclose', N 'false'
Go

Exec sp_dboption n 'host', N 'bulkcopy', N 'false'
Go

Exec sp_dboption n 'host', N 'trunc. log', N 'false'
Go

Exec sp_dboption n 'host', n'torn page detection ', n'true'
Go

Exec sp_dboption n 'host', N 'read only', N 'false'
Go

Exec sp_dboption n 'host', N 'dbo use', N 'false'
Go

Exec sp_dboption n 'host', N 'single ', N 'false'
Go

Exec sp_dboption n 'host', n'autoshrink ', n'false'
Go

Exec sp_dboption n 'host', n'ansi null default', n'false'
Go

Exec sp_dboption n 'host', N 'cursive trigger', N 'false'
Go

Exec sp_dboption n 'host', n'ansi nulls ', n'false'
Go

Exec sp_dboption n 'host', n'concat null yields null', n'false'
Go

Exec sp_dboption n 'host', n'cursor close on commit ', n'false'
Go

Exec sp_dboption n 'host', n'default to local cursor ', n'false'
Go

Exec sp_dboption n 'host', n' quoted identifier ', n' false'
Go

Exec sp_dboption n 'host', n'ansi warnings', n'false'
Go

Exec sp_dboption n 'host', n'auto create statistics ', n'true'
Go

Exec sp_dboption n 'host', n'auto update statistics ', n'true'
Go

Use [host]
Go

/***** Object: Table [DBO]. [groupaccess] script Date: 13:16:31 ******/
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [groupaccess] ') and objectproperty (ID, n'isusertable') = 1)
Drop table [DBO]. [groupaccess]
Go

/***** Object: Table [DBO]. [groupaccounts] script Date: 13:16:31 ******/
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [groupaccounts] ') and objectproperty (ID, n'isusertable') = 1)
Drop table [DBO]. [groupaccounts]
Go

/***** Object: Table [DBO]. [groupipaccess] script Date: 13:16:31 ******/
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [groupipaccess] ') and objectproperty (ID, n'isusertable') = 1)
Drop table [DBO]. [groupipaccess]
Go

/***** Object: Table [DBO]. [useraccess] script Date: 13:16:31 ******/
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [useraccess] ') and objectproperty (ID, n'isusertable') = 1)
Drop table [DBO]. [useraccess]
Go

/***** Object: Table [DBO]. [useraccounts] script Date: 13:16:31 ******/
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [useraccounts] ') and objectproperty (ID, n'isusertable') = 1)
Drop table [DBO]. [useraccounts]
Go

/***** Object: Table [DBO]. [useripaccess] script Date: 13:16:31 ******/
If exists (select * From DBO. sysobjects where id = object_id (n' [DBO]. [useripaccess] ') and objectproperty (ID, n'isusertable') = 1)
Drop table [DBO]. [useripaccess]
Go

/***** Object: Table [DBO]. [groupaccess] script Date: 13:16:34 ******/
Create Table [DBO]. [groupaccess] (
[Indexno] [int] Null,
[Username] [nvarchar] (50) Collate chinese_prc_ci_as null,
[Access] [nvarchar] (200) Collate chinese_prc_ci_as null,
[GAID] [int] identity (1, 1) not null
) On [primary]
Go

/***** Object: Table [DBO]. [groupaccounts] script Date: 13:16:36 ******/
Create Table [DBO]. [groupaccounts] (
[Username] [nvarchar] (50) Collate chinese_prc_ci_as null,
[Access] [nvarchar] (200) Collate chinese_prc_ci_as null,
[Notes] [nvarchar] (200) Collate chinese_prc_ci_as null,
[Gasid] [int] identity (1, 1) not null
) On [primary]
Go

/***** Object: Table [DBO]. [groupipaccess] script Date: 13:16:36 ******/
Create Table [DBO]. [groupipaccess] (
[Indexno] [int] Null,
[Username] [nvarchar] (50) Collate chinese_prc_ci_as null,
[Access] [nvarchar] (200) Collate chinese_prc_ci_as null,
[Gipaid] [int] identity (1, 1) not null
) On [primary]
Go

/***** Object: Table [DBO]. [useraccess] script Date: 13:16:37 ******/
Create Table [DBO]. [useraccess] (
[Indexno] [int] Null,
[Username] [nvarchar] (50) Collate chinese_prc_ci_as null,
[Access] [nvarchar] (200) Collate chinese_prc_ci_as null,
[Uaid] [int] identity (1, 1) not null
) On [primary]
Go

/***** Object: Table [DBO]. [useraccounts] script Date: 13:16:37 ******/
Create Table [DBO]. [useraccounts] (
[ID] [int] identity (1, 1) not null,
[Username] [nvarchar] (50) Collate chinese_prc_ci_as not null,
[Password] [nvarchar] (50) Collate chinese_prc_ci_as null,
[Disable] [bit] not null,
[Access] [nvarchar] (255) Collate chinese_prc_ci_as null,
[Changepass] [bit] not null,
[Passtype] [tinyint] not null,
[Expiration] [smalldatetime] not null,
[Expirationtype] [tinyint] not null,
[Skey] [nvarchar] (50) Collate chinese_prc_ci_as null,
[Relpaths] [bit] not null,
[Homedir] [nvarchar] (255) Collate chinese_prc_ci_as null,
[Messagefile] [nvarchar] (255) Collate chinese_prc_ci_as null,
[Maxusers] [int] not null,
[Maxup] [int] not null,
[Maxdown] [int] not null,
[Ratioup] [int] Null,
[Ratiodown] [int] Null,
[Ratiocredit] [float] Null,
[Ratiotype] [tinyint] Null,
[Quotaenable] [bit] not null,
[Quotamax] [int] not null,
[Quotacurrent] [int] not null,
[Groups] [nvarchar] (255) Collate chinese_prc_ci_as null,
[Privilege] [tinyint] not null,
[Lockhomedir] [bit] not null
) On [primary]
Go

/***** Object: Table [DBO]. [useripaccess] script Date: 13:16:38 ******/
Create Table [DBO]. [useripaccess] (
[Indexno] [smallint] Null,
[Username] [nvarchar] (50) Collate chinese_prc_ci_as null,
[Access] [nvarchar] (200) Collate chinese_prc_ci_as null,
[Uipaid] [int] identity (1, 1) not null
) On [primary]
Go

Alter table [DBO]. [groupaccess] With nocheck add
Constraint [pk_groupaccess] primary key clustered
(
[GAID]
) On [primary]
Go

Alter table [DBO]. [groupaccounts] With nocheck add
Constraint [pk_groupaccounts] primary key clustered
(
[Gasid]
) On [primary]
Go

Alter table [DBO]. [groupipaccess] With nocheck add
Constraint [pk_groupipaccess] primary key clustered
(
[Gipaid]
) On [primary]
Go

Alter table [DBO]. [useraccess] With nocheck add
Constraint [pk_useraccess] primary key clustered
(
[Uaid]
) On [primary]
Go

Alter table [DBO]. [useraccounts] With nocheck add
Constraint [pk_useraccounts] primary key clustered
(
[ID]
) On [primary]
Go

Alter table [DBO]. [useripaccess] With nocheck add
Constraint [pk_useripaccess] primary key clustered
(
[Uipaid]
) On [primary]
Go

Alter table [DBO]. [useraccounts] With nocheck add
Constraint [df_useraccounts_disable] default (0) for [disable],
Constraint [df_useraccounts_changepass] default (1) for [changepass],
Constraint [df_useraccounts_passtype] default (0) for [passtype],
Constraint [df_useraccounts_expirationtype] default (1) for [expirationtype],
Constraint [df_useraccounts_relpaths] default (0) for [relpaths],
Constraint [df_useraccounts_maxusers] default (-1) for [maxusers],
Constraint [df_useraccounts_maxup] default (0) for [maxup],
Constraint [df_useraccounts_maxdown] default (0) for [maxdown],
Constraint [df_useraccounts_ratioup] default (1) for [ratioup],
Constraint [df_useraccounts_ratiodown] default (1) for [ratiodown],
Constraint [df_useraccounts_ratiocredit] default (0) for [ratiocredit],
Constraint [df_useraccounts_ratiotype] default (0) for [ratiotype],
Constraint [df_useraccounts_quotaenable] default (1) for [quotaenable],
Constraint [df_useraccounts_quotamax] default (0) for [quotamax],
Constraint [df_useraccounts_quotacurrent] default (0) for [quotacurrent],
Constraint [df_useraccounts_privilege] default (0) for [privilege],
Constraint [df_useraccounts_lockhomedir] default (1) for [lockhomedir],
Constraint [ix_useraccounts] unique nonclustered
(
[Username]
) On [primary]
Go

Exec sp_addextendedproperty n 'Ms _ description', N 'Directory authorization', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'access'
Go
Exec sp_addextendedproperty n 'Ms _ description', n' whether to allow Password Change ', n'user', n'dbo', n'table', n'useraccounts ', N 'column ', N 'changepass'
Go
Exec sp_addextendedproperty n 'Ms _ description', n'account disabled? ', n'user', n'dbo', n'table', n'useraccounts ', N 'column ', N 'disable'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'expiration time', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'expiration'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'expiration type', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'expirationtype'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'User Group', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'groups'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'main directory', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'homedir'
Go
Exec sp_addextendedproperty n 'Ms _ description', n' whether it is locked in the main directory ', n'user', n'dbo', n'table', n'useraccounts ', N 'column ', N 'lockhomedir'
Go
Exec sp_addextendedproperty n 'Ms _ description', n'maximum download rate', n'user', n'dbo', n'table', n'useraccounts ', N 'column', N 'maxlow'
Go
Exec sp_addextendedproperty n 'Ms _ description', n'maximum upload rate', n'user', n'dbo', n'table', n'useraccounts ', N 'column ', N 'maxup'
Go
Exec sp_addextendedproperty n 'Ms _ description', n'maximum login user', n'user', n'dbo', n'table', n'useraccounts ', N 'column ', N 'maxusers'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'message file', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'messagefile'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'password type', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'passtype'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'Password', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'Password'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'administrative authorization', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'privilege'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'current quota ', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'quotacurrent'
Go
Exec sp_addextendedproperty n 'Ms _ description', n' enable Disk Quota ', n'user', n'dbo', n'table', n'useraccounts ', N 'column', n' quotaenable'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'maximum limited', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'quotamax'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'Download rate', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', n' ratiodown'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'upload ratio ', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', n' ratioup'
Go
Exec sp_addextendedproperty n 'Ms _ description', N 'username', N 'user', N 'dbo', N 'table', N 'useraccounts', N 'column ', N 'username'

Go

Code implemented by Asp.net:
Using system;
Using system. Web. Security;
Using system. configuration;
Using system. Data;
Using system. Data. sqlclient;

Namespace host
{
/// <Summary>
/// FTP summary.
/// </Summary>
Public class FTP
{
Private sqlconnection conhost;

Public String username; // User Name
Public String password; // Password
Public bool disable; // Disabled Account true: Disabled Account false: enabled account
Public String access; // directory/IP address access rule
Public byte passtype; // password type 0: Rule password 1: otp s/key md4 2: otp s/key MD5
Public bool changepass; // you can change the password to true: false: Disabled.
Public datetime expiration; // expiration time
Public byte expirationtype; // expiration type 1: Delete 2: Disabled
Public String skey;
Public bool relpaths; // required for secure connection. True: required. False: not required.
Public String homedir; // main directory
Public String messagefile; // message file
Public int maxusers; // The maximum number of users.
Public int maxup; // maximum upload Rate
Public int maxdown; // maximum download rate
Public byte ratiotype; // ratio type
Public int ratioup; // upload Rate
Public int ratiodown; // download rate
Public float ratiocredit; // rate of trust
Public bool quotaenable; // allowed quota true: allowed false: Disabled
Public int quotamax; // maximum quota
Public int quotacurrent; // current quota
Public String groups; // User Group
Public byte privilege; // management permission 0: no permission 1: System Administrator 2: Group Administrator 3: domain administrator 4: Read-Only Administrator
Public bool lockhomedir; // locked in the main directory. True: Locked. False: unlocked.

Public FTP ()
{
//
// Todo: add the constructor logic here
//
Username = "guest ";
Password = "guest ";
Disable = false;
Access = "";
Passtype = 0;
Changepass = true;
Expiration = datetime. Now. date;
Expirationtype = 1;
Skey = "";
Relpaths = false;
Homedir = "";
Messagefile = "";
Maxusers = 1;
Maxup = 100*1024; // 100 K
Maxdown = 100*1024; // 100 K
Ratiotype = 0;
Ratioup = 1;
Ratiodown = 1;
Ratiocredit = 0;
Quotaenable = true;
Quotamax = 10*1024*1024; // 10 m
Quotacurrent = 0;
Groups = "";
Privilege = 0;
Lockhomedir = true;

Conhost = new sqlconnection (configurationsettings. receivettings ["constring"]);
Conhost. open ();
}

~ FTP ()
{
Conhost. Close ();
}

Public void add ()
{
// Add an account
Sqlcommand into add = new sqlcommand ("insert into useraccounts (username, password, disable, access, changepass, passtype, expiration, expirationtype, skey, relpaths, homedir, messagefile, maxusers, maxup, maxdown, ratioup, ratiodown, ratiocredit, ratiotype, quotaenable, quotamax, quota, groups, privilege, lockhomedir) values (@ username, @ password, @ disable, @ access, @ changepass, @ passtype, @ expiration, @ expirationtype, @ skey, @ relpaths, @ homedir, @ messagefile, @ maxusers, @ maxup, @ maxdown, @ ratioup, @ ratiodown, @ ratiocredit, @ ratiotype, @ quotaenable, @ quotamax, @ quotacurrent, @ groups, @ privilege, @ lockhomedir) ", conhost );

Using Add. Parameters. Add ("@ username", username );
Using Add. Parameters. Add ("@ password", pass ());
Parameter Add. Parameters. Add ("@ disable", disable );
Using Add. Parameters. Add ("@ access", access );
Using Add. Parameters. Add ("@ changepass", changepass );
Parameters Add. Parameters. Add ("@ passtype", passtype );
Using Add. Parameters. Add ("@ expiration", expiration );
Using Add. Parameters. Add ("@ expirationtype", expirationtype );
Using Add. Parameters. Add ("@ skey", skey );
Using Add. Parameters. Add ("@ relpaths", relpaths );
Using Add. Parameters. Add ("@ homedir", homedir );
Parameters Add. Parameters. Add ("@ messagefile", messagefile );
Using Add. Parameters. Add ("@ maxusers", maxusers );
Using Add. Parameters. Add ("@ maxup", maxup );
Using Add. Parameters. Add ("@ maxdown", maxdown );
Using Add. Parameters. Add ("@ ratioup", ratioup );
Using Add. Parameters. Add ("@ ratiodown", ratiodown );
Using Add. Parameters. Add ("@ ratiocredit", ratiocredit );
Using Add. Parameters. Add ("@ ratiotype", ratiotype );
Using Add. Parameters. Add ("@ quotaenable", quotaenable );
Using Add. Parameters. Add ("@ quotamax", quotamax );
Parameter Add. Parameters. Add ("@ quotacurrent", quotacurrent );
Using Add. Parameters. Add ("@ groups", groups );
Using Add. Parameters. Add ("@ privilege", privilege );
Using Add. Parameters. Add ("@ lockhomedir", lockhomedir );
// Configure Add. Parameters. Add ("@",);

Revoke Add. executenonquery ();
}

Public String pass ()
{
// Password encryption
Random rnm = new random ();
Char A = (char) (rnm. Next (97,123 ));
Char B = (char) (rnm. Next (97,123 ));
String Password = string. Format ("{0} {1} {2}", a, B, password );
Password = formsauthentication. hashpasswordforstoringinconfigfile (password, "MD5 ");
Password = string. Format ("{0} {1} {2}", a, B, password. toupper ());
Return password;
}

Public bool modifypass (string oldpass, string newpass)
{
// Change the password
Return true;
}
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.