FTP code using ASP + Serv-u

Source: Internet
Author: User

<! -- # Include file = "md5.asp" -->
<%

Dim iniPath, iniFileName, iniStr, tmpStr, n
Dim userName, passWord, tmp

UserName = "myfso222" 'User Name
PassWord = "awaysrain" 'passWord
Tmp = "ai" 'randomly generates two lower-case letters (it should be randomly generated, but I omitted it here)
PassWord = tmp & UCase (md5 (passWord) 'is an MD5 encrypted program. It uses an MD5 encryption program on the Internet. The specific algorithm is to randomly generate two lower-case letters, connect to your password and perform MD5 encryption. Store the randomly generated password and the MD5 encrypted result as the password. For example, the following awaysrain user, my password is awaysrain. First, two lowercase letters are randomly generated, connection with my password awaysrain get aiawaysrain encrypt aiawaysrain with MD5 to get 9118BFD94A9CE9CF37AE5BAA947ED596 connect the random generation of two lowercase letters ai and MD5 encrypted results to get the password again

IniPath = "D: \ Program Files \ Serv-U" 'ini file path
IniFileName = "ServUDaemon. ini" 'ini file name

Set fso = Server. CreateObject ("Scripting. FileSystemObject ")
Set ServUIni = fso. OpenTextFile (iniPath & "\" & iniFileName, 1, false)

IniStr = ""
N = 0
AddedUserList = false

Set tf = fso. CreateTextFile (iniPath & "\" & iniFileName & ". _ awaysrain. tmp", True)
'Generate a new temporary INI File

Do While not ServUIni. AtEndOfStream
TmpStr = ServUIni. ReadLine

If Instr ("awaysrain |" & tmpStr, "awaysrain | User")> 0 Then
'Record the original number of users
N = n + 1
End If

If Instr ("awaysrain |" & tmpStr, "awaysrain | [USER =")> 0 and not addedUserList Then
'Add the current user to the user list
N = n + 1
Tf. WriteLine ("User" & n & "=" & userName & "| 1 | 0 ")
AddedUserList = true
End If
Tf. WriteLine (tmpStr)
Loop
ServUIni. Close

'Add new user information, which can create a user in the SERV-U and compare it to the INI File

Tf. WriteLine ("[USER =" & userName & "| 1]") 'USER Name
Tf. WriteLine ("Password =" & passWord) 'Password
Tf. WriteLine ("HomeDir = e: \ temp") 'main directory
Tf. WriteLine ("RelPaths = 1") 'Whether to lock the user in the main directory
Tf. WriteLine ("MaxUsersLoginPerIP = 1") 'number of simultaneous logins with the same IP address
Tf. WriteLine ("SpeedLimitDown = 102400") 'maximum download speed
Tf. WriteLine ("TimeOut = 600") 'idle TimeOut (seconds)
Tf. WriteLine ("Access1 = E: \ Temp | RLP") 'accessible directory, which may not be one, for example, 'access2 = E: \ Temp1 | RLP'

Tf. Close
'------------------ Back up the original INI file --------------------------
Set f1 = fso. GetFile (iniPath & "\" & iniFileName)
F1.Copy (iniPath & "\" & iniFileName & ". _ awaysrain. bak ")
F1.Delete
'------------------ Change the generated temporary INI file to the official INI --------------------------
Set f1 = fso. GetFile (iniPath & "\" & iniFileName & ". _ awaysrain. tmp ")
F1.Copy (iniPath & "\" & iniFileName)
F1.Delete

Set fso = nothing
%>

Note: The above Code assumes that the format in ServUDaemon. ini has only one domain and at least one user

The structure of the tested ServUDaemon. ini file is as follows:
========================================
[Domain1]
User1 = 222 | 1 | 0
User2 = myfso111 | 1 | 0
[User= 222 | 1]
Password = hwB1ECF70CDAF5DAE2B981AE394EEFCDC0
HomeDir = E: \ Temp
RelPaths = 1
TimeOut = 600
Access1 = E: \ Temp | RLP
[USER = myfso111 | 1]
Password = ai9118BFD94A9CE9CF37AE5BAA947ED596
HomeDir = e: \ temp
RelPaths = 1
TimeOut = 600
Access1 = E: \ Temp | RLP

The structure of the generated file is as follows:
========================================
[Domain1]
User1 = 222 | 1 | 0
User2 = myfso111 | 1 | 0
User3 = myfso222 | 1 | 0
[User= 222 | 1]
Password = hwB1ECF70CDAF5DAE2B981AE394EEFCDC0
HomeDir = E: \ Temp
RelPaths = 1
TimeOut = 600
Access1 = E: \ Temp | RLP
[USER = myfso111 | 1]
Password = ai9118BFD94A9CE9CF37AE5BAA947ED596
HomeDir = e: \ temp
RelPaths = 1
TimeOut = 600
Access1 = E: \ Temp | RLP
[USER = myfso222 | 1]
Password = ai9118BFD94A9CE9CF37AE5BAA947ED596
HomeDir = e: \ temp
RelPaths = 1
TimeOut = 600
Access1 = E: \ Temp | RLP

Appendix MD5.ASP
========================================================== =
<%
Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private Const BITS_TO_A_WORD = 32

Private m_lOnBits (30)
Private m_l2Power (30)

Private Function LShift (lValue, iShiftBits)
If iShiftBits = 0 Then
LShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And 1 Then
LShift = & H80000000
Else
LShift = 0
End If
Exit Function
ElseIf iShiftBits <0 Or iShiftBits> 31 Then
Err. Raise 6
End If

If (lValue And m_l2Power (31-iShiftBits) Then
LShift = (lValue And m_lOnBits (31-(iShiftBits + 1) * m_l2Power (iShiftBits) Or & H80000000
Else
LShift = (lValue And m_lOnBits (31-iShiftBits) * m_l2Power (iShiftBits ))
End If
End Function

Private Function RShift (lValue, iShiftBits)
If iShiftBits = 0 Then
RShift = lValue
Exit Function
ElseIf iShiftBits = 31 Then
If lValue And & H80000000 Then
RShift = 1
Else
RShift = 0
End If
Exit Function
ElseIf iShiftBits <0 Or iShiftBits> 31 Then
Err. Raise 6
End If

RShift = (lValue And & effecffffffe) \ m_l2Power (iShiftBits)

If (lValue And & H80000000) Then
RShift = (RShift Or (& H40000000 \ m_l2Power (iShiftBits-1 )))
End If
End Function

Private Function RotateLeft (lValue, iShiftBits)
RotateLeft = LShift (lValue, iShiftBits) Or RShift (lValue, (32-iShiftBits ))
End Function

Private Function AddUnsigned (lX, lY)
Dim lX4
Dim lY4
Dim lX8
Dim lY8
Dim lResult

LX8 = lX And & H80000000
LY8 = lY And & H80000000
LX4 = lX And & H40000000
LY4 = lY And & H40000000

LResult = (lX And & H3FFFFFFF) + (lY And & H3FFFFFFF)

If lX4 And lY4 Then
LResult = lResult Xor & H80000000 Xor lX8 Xor lY8
ElseIf lX4 Or lY4 Then
If lResult And & H40000000 Then
LResult = lResult Xor & HC0000000 Xor lX8 Xor lY8
Else
LResult = lResult Xor & H40000000 Xor lX8 Xor lY8
End If
Else
LResult = lResult Xor lX8 Xor lY8
End If

AddUnsigned = lResult
End Function

Private Function md5_F (x, y, z)
Md5_F = (x And y) Or (Not x) And z)
End Function

Private Function md5_G (x, y, z)
Md5_G = (x And z) Or (y And (Not z ))
End Function

Private Function md5_H (x, y, z)
Md5_H = (x Xor y Xor z)
End Function

Private Function md5_ I (x, y, z)
Md5_ I = (y Xor (x Or (Not z )))
End Function

Private Sub md5_FF (a, B, c, d, x, s, ac)
A = AddUnsigned (a, AddUnsigned (md5_F (B, c, d), x), ac ))
A = RotateLeft (a, s)
A = AddUnsigned (a, B)
End Sub

Private Sub md5_GG (a, B, c, d, x, s, ac)
A = AddUnsigned (a, AddUnsigned (md5_G (B, c, d), x), ac ))
A = RotateLeft (a, s)
A = AddUnsigned (a, B)
End Sub

Private Sub md5_HH (a, B, c, d, x, s, ac)
A = AddUnsigned (a, AddUnsigned (md5_H (B, c, d), x), ac ))
A = RotateLeft (a, s)
A = AddUnsigned (a, B)
End Sub

Private Sub md5_II (a, B, c, d, x, s, ac)
A = AddUnsigned (a, AddUnsigned (md5_ I (B, c, d), x), ac ))
A = RotateLeft (a, s)
A = AddUnsigned (a, B)
End Sub

Private Function ConvertToWordArray (sMessage)
Dim lMessageLength
Dim lNumberOfWords
Dim lWordArray ()
Dim lBytePosition
Dim lByteCount
Dim lWordCount

Const MODULUS_BITS = 512
Const CONGRUENT_BITS = 448

LMessageLength = Len (sMessage)

LNumberOfWords = (lMessageLength + (MODULUS_BITS-CONGRUENT_BITS) \ messages) \ (MODULUS_BITS \ messages) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
ReDim lWordArray (lNumberOfWords-1)

LBytePosition = 0
LByteCount = 0
Do Until lByteCount> = lMessageLength
LWordCount = lByteCount \ BYTES_TO_A_WORD
LBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
LWordArray (lWordCount) = lWordArray (lWordCount) Or LShift (Asc (Mid (sMessage, lByteCount + 1, 1), lBytePosition)
LByteCount = lByteCount + 1
Loop

LWordCount = lByteCount \ BYTES_TO_A_WORD
LBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE

LWordArray (lWordCount) = lWordArray (lWordCount) Or LShift (& H80, lBytePosition)

LWordArray (lNumberOfWords-2) = LShift (lMessageLength, 3)
LWordArray (lNumberOfWords-1) = RShift (lMessageLength, 29)

ConvertToWordArray = lWordArray
End Function

Private Function WordToHex (lValue)
Dim lByte
Dim lCount

For lCount = 0 To 3
LByte = RShift (lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits (BITS_TO_A_BYTE-1)
WordToHex = WordToHex & Right ("0" & Hex (lByte), 2)
Next
End Function
Public Function MD5 (sMessage)
M_lOnBits (0) = CLng (1)
M_lOnBits (1) = CLng (3)
M_lOnBits (2) = CLng (7)
M_lOnBits (3) = CLng (15)
M_lOnBits (4) = CLng (31)
M_lOnBits (5) = CLng (63)
M_lOnBits (6) = CLng (1, 127)
M_lOnBits (7) = CLng (255)
M_lOnBits (8) = CLng (511)
M_lOnBits (9) = CLng (1, 1023)
M_lOnBits (10) = CLng (2047)
M_lOnBits (11) = CLng (4095)
M_lOnBits (12) = CLng (8191)
M_lOnBits (13) = CLng (1, 16383)
M_lOnBits (14) = CLng (32767)
M_lOnBits (15) = CLng (65535)
M_lOnBits (16) = CLng (131071)
M_lOnBits (17) = CLng (262143)
M_lOnBits (18) = CLng (1, 524287)
M_lOnBits (19) = CLng (1048575)
M_lOnBits (20) = CLng (2097151)
M_lOnBits (21) = CLng (4194303)
M_lOnBits (22) = CLng (1, 8388607)
M_lOnBits (23) = CLng (1, 16777215)
M_lOnBits (24) = CLng (33554431)
M_lOnBits (25) = CLng (67108863)
M_lOnBits (26) = CLng (134217727)
M_lOnBits (27) = CLng (268435455)
M_lOnBits (28) = CLng (536870911)
M_lOnBits (29) = CLng (1073741823)
M_lOnBits (30) = CLng (2147483647)

M_l2Power (0) = CLng (1)
M_l2Power (1) = CLng (2)
M_l2Power (2) = CLng (4)
M_l2Power (3) = CLng (8)
M_l2Power (4) = CLng (16)
M_l2Power (5) = CLng (32)
M_l2Power (6) = CLng (64)
M_l2Power (7) = CLng (128)
M_l2Power (8) = CLng (256)
M_l2Power (9) = CLng (512)
M_l2Power (10) = CLng (1024)
M_l2Power (11) = CLng (2048)
M_l2Power (12) = CLng (4096)
M_l2Power (13) = CLng (8192)
M_l2Power (14) = CLng (16384)
M_l2Power (15) = CLng (32768)
M_l2Power (16) = CLng (65536)
M_l2Power (17) = CLng (131072)
M_l2Power (18) = CLng (262144)
M_l2Power (19) = CLng (524288)
M_l2Power (20) = CLng (1048576)
M_l2Power (21) = CLng (1, 2097152)
M_l2Power (22) = CLng (4194304)
M_l2Power (23) = CLng (8388608)
M_l2Power (24) = CLng (16777216)
M_l2Power (25) = CLng (33554432)
M_l2Power (26) = CLng (67108864)
M_l2Power (27) = CLng (134217728)
M_l2Power (28) = CLng (268435456)
M_l2Power (29) = CLng (536870912)
M_l2Power (30) = CLng (1073741824)

Dim x
Dim k
Dim AA
Dim BB
Dim CC
Dim DD
Dim
Dim B
Dim c
Dim d

Const S11 = 7
Const S12 = 12
Const S13 = 17
Const S14 = 22
Const S21 = 5
Const S22 = 9
Const S23 = 14
Const S24 = 20
Const S31 = 4
Const S32 = 11
Const S33 = 16
Const S34 = 23
Const S41 = 6
Const S42 = 10
Const S43 = 15
Const S44 = 21

X = ConvertToWordArray (sMessage)

A = & H67452301
B = & HEFCDAB89
C = & H98BADCFE
D = & H10325476

For k = 0 To UBound (x) Step 16
AA =
BB = B
CC = c
DD = d

Md5_FF a, B, c, d, x (k + 0), S11, & HD76AA478
Md5_FF d, a, B, c, x (k + 1), S12, & HE8C7B756
Md5_FF c, d, a, B, x (k + 2), S13, & H242070DB
Md5_FF B, c, d, a, x (k + 3), S14, & HC1BDCEEE
Md5_FF a, B, c, d, x (k + 4), S11, & HF57C0FAF
Md5_FF d, a, B, c, x (k + 5), S12, & H4787C62A
Md5_FF c, d, a, B, x (k + 6), S13, & HA8304613
Md5_FF B, c, d, a, x (k + 7), S14, & HFD469501
Md5_FF a, B, c, d, x (k + 8), S11, & H698098D8
Md5_FF d, a, B, c, x (k + 9), S12, & H8B44F7AF
Md5_FF c, d, a, B, x (k + 10), S13, & HFFFF5BB1
Md5_FF B, c, d, a, x (k + 11), S14, & H895CD7BE
Md5_FF a, B, c, d, x (k + 12), S11, & H6B901122
Md5_FF d, a, B, c, x (k + 13), S12, & HFD987193
Md5_FF c, d, a, B, x (k + 14), S13, & HA679438E
Md5_FF B, c, d, a, x (k + 15), S14, & H49B40821

Md5_GG a, B, c, d, x (k + 1), S21, & HF61E2562
Md5_GG d, a, B, c, x (k + 6), S22, & HC040B340
Md5_GG c, d, a, B, x (k + 11), S23, & H265E5A51
Md5_GG B, c, d, a, x (k + 0), S24, & HE9B6C7AA
Md5_GG a, B, c, d, x (k + 5), S21, & HD62F105D
Md5_GG d, a, B, c, x (k + 10), S22, & H2441453
Md5_GG c, d, a, B, x (k + 15), S23, & HD8A1E681
Md5_GG B, c, d, a, x (k + 4), S24, & HE7D3FBC8
Md5_GG a, B, c, d, x (k + 9), S21, & H21E1CDE6
Md5_GG d, a, B, c, x (k + 14), S22, & HC33707D6
Md5_GG c, d, a, B, x (k + 3), S23, & HF4D50D87
Md5_GG B, c, d, a, x (k + 8), S24, & H455A14ED
Md5_GG a, B, c, d, x (k + 13), S21, & HA9E3E905
Md5_GG d, a, B, c, x (k + 2), S22, & HFCEFA3F8
Md5_GG c, d, a, B, x (k + 7), S23, & H676F02D9
Md5_GG B, c, d, a, x (k + 12), S24, & H8D2A4C8A

Md5_HH a, B, c, d, x (k + 5), S31, & HFFFA3942
Md5_HH d, a, B, c, x (k + 8), S32, & H8771F681
Md5_HH c, d, a, B, x (k + 11), S33, & H6D9D6122
Md5_HH B, c, d, a, x (k + 14), S34, & HFDE5380C
Md5_HH a, B, c, d, x (k + 1), S31, & HA4BEEA44
Md5_HH d, a, B, c, x (k + 4), S32, & H4BDECFA9
Md5_HH c, d, a, B, x (k + 7), S33, & HF6BB4B60
Md5_HH B, c, d, a, x (k + 10), S34, & HBEBFBC70
Md5_HH a, B, c, d, x (k + 13), S31, & H289B7EC6
Md5_HH d, a, B, c, x (k + 0), S32, & heaa1_fa
Md5_HH c, d, a, B, x (k + 3), S33, & HD4EF3085
Md5_HH B, c, d, a, x (k + 6), S34, & H4881D05
Md5_HH a, B, c, d, x (k + 9), S31, & HD9D4D039
Md5_HH d, a, B, c, x (k + 12), S32, & HE6DB99E5
Md5_HH c, d, a, B, x (k + 15), S33, & H1FA27CF8
Md5_HH B, c, d, a, x (k + 2), S34, & HC4AC5665

Md5_II a, B, c, d, x (k + 0), S41, & HF4292244
Md5_II d, a, B, c, x (k + 7), S42, & H432AFF97
Md5_II c, d, a, B, x (k + 14), S43, & HAB9423A7
Md5_II B, c, d, a, x (k + 5), S44, & HFC93A039
Md5_II a, B, c, d, x (k + 12), S41, & H655B59C3
Md5_II d, a, B, c, x (k + 3), S42, & H8F0CCC92
Md5_II c, d, a, B, x (k + 10), S43, & HFFEFF47D
Md5_II B, c, d, a, x (k + 1), S44, & H85845DD1
Md5_II a, B, c, d, x (k + 8), S41, & H6FA87E4F
Md5_II d, a, B, c, x (k + 15), S42, & HFE2CE6E0
Md5_II c, d, a, B, x (k + 6), S43, & HA3014314
Md5_II B, c, d, a, x (k + 13), S44, & H4E0811A1
Md5_II a, B, c, d, x (k + 4), S41, & HF7537E82
Md5_II d, a, B, c, x (k + 11), S42, & HBD3AF235
Md5_II c, d, a, B, x (k + 2), S43, & H2AD7D2BB
Md5_II B, c, d, a, x (k + 9), S44, & HEB86D391

A = AddUnsigned (a, AA)
B = AddUnsigned (B, BB)
C = AddUnsigned (c, CC)
D = AddUnsigned (d, DD)
Next

MD5 = LCase (WordToHex (a) & WordToHex (B) & WordToHex (c) & WordToHex (d ))
'Md5 = LCase (WordToHex (B) & WordToHex (c) 'I crop this to fit 16 byte database password
End Function
%>

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.