Preface
⑴ In public places such as electronic reading rooms, computer rooms, and Internet cafes, due to frequent use and delayed maintenance, it is common for output systems such as floppy drives to be damaged. The output is often discovered when you need to output the processed data. There is a lot of frustration when the equipment does not work, and in order to save costs, many computer rooms do not have all the necessary output devices on the computers connected to the network.
⑵ As computers become more popular, people become more and more dependent on them. Many office tasks are inseparable from computers. In other words, office workers' computers began to store a lot of important office and private data. In most cases, these data are unique, which means that their owners do not make a copy of them and store them on different computers. Their security depends entirely on the stability of their owners' computers.
⑶ The popularity of the Internet has shortened the distance between people and made communication more convenient. However, we need to access the Internet every day in different places such as homes, offices, and Internet cafes. How can we continue to edit a document? Perhaps you can carry these data with you through a mobile storage device such as a USB flash drive or a mobile hard disk, but it is not very convenient to carry one more such device, especially a mobile hard disk, and different places, different devices, and different operating systems are not suitable for you. The support of USB flash drives or mobile hard drives is not the same, and the computer skills of users are also different.
...
Due to these facts, network storage has emerged as a necessity.
Currently, there are many ways to implement network storage, such as email, FTP, Network Places, HTTP, etc. Among them, FTP has the most powerful functions, but it is a little complicated to use. A lot of settings are enough to deter many people. Especially when the number of users is unpredictable, the settings for users with special needs will be more cumbersome; email is familiar to everyone. Yes, but within the local area network, it is not a good way to exchange financial, labor and other documents and information in this way. Moreover, when your file is large enough, it will have a fatal impact on the mail space; Network Neighbors can be shared by specifying it on this machine. Web folders and placed files, users within a certain range can access these files. However, the scope of this method is quite limited. Usually only users in the same DNS segment address can access it smoothly. Others, especially users on the Internet, It's difficult to use, and like email, it's not intuitive to use. Many times you have to search through many lists of computers to get the resource you want! The network storage methods mentioned above also have a common shortcoming: that is, administrators cannot have a clear understanding of the usage of files stored in network storage, and can only decide whether to space them based on the storage time of the files. Clean up.
This article introduces a relatively simple network storage method implemented through HTTP. This method is implemented on the WINDOWS platform through IIS and ASP/ASP.NET. It is not only simple to use and can upload any type of file, but also can limit the space used by the user. A transmission can be as small as 20 bytes and as large as Hundreds of megabytes can be managed by administrators. In addition, the security of files is also guaranteed. Only file owners and authorized persons can restore files. Understanding the data structure in the second major point and the upload source code in the third major point of this article will help you create a network storage yourself. You will not have to rely on the free network storage provided on the market to store sensitive data files inside the network. Your safety is firmly in your own hands.
Overview and basic functions
Install a server as a network storage host. The operating system uses the Windows platform and is equipped with IIS5.0. Set up the WEB service and create a virtual website under the main website pointing to the network storage, such as: d:netspace spacenetmyspace. All asp and asp.net source codes are placed under the main website (such as: c:inetpubwwwroot), and d:netspacespacenetmyspace will place files uploaded by users (virtual website changes should also be made in the source code Adjust accordingly).
1. The basic database and structure used:
⑴ ftpsapce.mdb: has the table userlist, the basic structure of the table:
Id: sequence number, automatically generated;
Xh: User account, registration and verification generation;
Xm: User name, registration and verification generation;
Kl: User password, registration and verification generation;
Maxspace: The maximum limit of user space. The default value is used for registration. The administrator can reset it through management;
Nowspace: The amount of space currently occupied by the user;
Lastaccessday: the user’s last access time, for administrators to refer to when managing the space;
Fromday: user registration time;
Checkx: User verification flag.
⑵ Filelist.mdb: has the table files, the basic structure of the table:
Id: sequence number, automatically generated;
Filename: file name, generated by the upload system;
Fsize: file size value;
Xh: user account;
Upday: upload time;
Filescript: File description, which is the path and original file name of the file when the user uploads it, for reference when the user loads;
2. Basic functions
⑴ The user logs in to the main website, enters the main page of the website, and gives the user's basic information for user registration.
⑵ The administrator will review the user's registration information and set the user's maximum usage space.
⑶ Users who pass the review upload files to network storage. The system determines the legality of the user and the legality of the file, and registers the files and user information uploaded by the user in the database.
⑷ Approved users can reload or delete the files they uploaded through the download function.
⑸ The administrator manages the network space based on the user database and file database.
⑹ The expanded system allows authorized users to download files uploaded by authorized users.
The basic source code of the upload module
is limited by space. This article only gives the basic source code of the upload module. If you need more source code, you can request it from the author via email. The lines starting with *** in the source code are comments added by the author for the convenience of readers. . (The following is excerpted from upfile.aspx)
<%@ Page Language="VB" Debug="true" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.oledb" %>
<html>
<script language="vbscript" runat="server">
sub uploadfile(sender as object, e as eventargs)
if fileup.postedfile.contentlength<20 then
errors.text="You have to upload such a small file, just memorize it."
fileinfo.visible=false
exit sub
else
errors.text="Verification OK"
fileinfo.visible=true
end if
*** The above checks the uploaded file size
respace.text="0"
nowspace.text="0"
*** respace refers to the remaining space, nowspace refers to the used space
dim xh1 as string =user1.value
dim kl1 as string =pass1.value
*** xh1 refers to the account number, kl1 refers to the password
dim objconnstr as string="provider=microsoft.jet.oledb.4.0;data source="
& server.mappath("ftpspace.mdb")
*** The above two lines should be the same statement in the source code
dim objconn as oledbconnection = new oledbconnection(objconnstr)
dim sql1 as string="select * from userlist where xh='"+xh1+"' and kl='"+kl1+"'"
dim objrscc as oledbcommand= new oledbcommand(sql1,objconn)
objconn.open()
dim objrs as oledbdatareader = objrscc.executereader()
dimix as integer=0
dim max as long
dim now as long
while ix=0
if objrs.read() then
if objrs.item("xh")=xh1 then
if objrs.item("kl")=kl1 then
if objrs.item("checkx")=1 then
ix=ix+1
maxs=objrs.item("maxspace")
nows=objrs.item("nowspace")
end if
end if
end if
else
ix=-1
end if
end while
*** The above determines whether the account and password are legal
if ix<=0 then
errors.text="The account password is wrong! Or the user has not been authenticated, please wait for the administrator to authenticate!"
else
if fileup.postedfile.contentlength>maxs-nows then
if fileup.postedfile.contentlength>=maxs then
errors.text="The file length is greater than the allocated space and cannot be uploaded!"
else
errors.text="Insufficient free space, please delete old files!"
end if
*** The above determines the availability of user space
else
dim obj4str as string="provider=microsoft.jet.oledb.4.0;
data source=" & server.mappath("filelist.mdb")
*** The above two lines are the same statement in the source code dim obj4 as oledbconnection = new oledbconnection(obj4str)
dim sql10 as string="select * from files"
dim objrc1 as oledbcommand= new oledbcommand(sql10,obj4)
obj4.open()
dim objrsx as oledbdatareader = objrc1.executereader()
dim fn11 as long =0
while objrsx.read()
fn11=objrsx("filename")
end while
dim fn1 as string
fn1=cstr(fn11+1)
*** The above creates a unique main file name for users to upload files dim objc1str as string="provider=microsoft.jet.oledb.4.0;
data source=" & server.mappath("filelist.mdb")
*** The above two lines are the same statement in the source code dim objc1 as oledbconnection = new oledbconnection(objc1str)
dim sql3 as string="insert into files(filename,fsize, xh,filescript,upday)
values("+cstr(fn1)+","+cstr(fileup.postedfile.contentlength)+",'"
+xh1+"','"+fileup.postedfile.filename+"','"+cstr(now())+"')"
*** The above three lines are the same statement objc1.open() in the source code
dim objrs1 as oledbcommand=new oledbcommand(sql3,objc1)
dim fn2 as string
fn2="d:/netspace/spacenet/myspace/"&cstr(fn1)&".zip"
*** Give the absolute path and complete file name of the file uploaded by the user fsize.text=cstr(fileup.postedfile.contentlength)
ftype.text=fileup.postedfile.contenttype
fname.text=fileup.postedfile.filename
username.text=user1.value
fileup.postedfile.saveas(fn2)
objrs1.ExecuteNonQuery()
objrs.close
dim sql5 as string="update userlist set nowspace="+cstr(nows+fileup.postedfile.contentlength)+
",lastaccessday='"+cstr(now())+"' where xh='"+xh1+"'"
*** The above two lines are the same statement in the source code
dim objrnc as oledbcommand= new oledbcommand(sql5,objconn)
objrnc.executenonquery()
respace.text=cstr(maxs-nows-fileup.postedfile.contentlength)&"bytes."
nowspace.text=cstr(nows+fileup.postedfile.contentlength)&"bytes."
*** The above is used for uploading, and the user's total used space and total remaining space are calculated end if
end if
end sub
</script>
<body>
<form enctype="multipart/form-data" runat="server">
<table>
<tr><td>Account:</td><td><input id="user1" runat="server"></td></tr>
<tr><td>Password:</td><td><input type="password" id="pass1" runat="server"></td></tr>
<tr><td>File:</td><td><input type="file" id="fileup" runat="server"></td></tr>
<tr><td></td><td><asp:button id="upload" onclick="uploadfile" text="Upload"
runat="server"/></td></tr>
</table>
</form><hr>
<div id="fileinfo" visible="false" runat="server">
Original file name:<asp:label id="fname" runat="server"/><br>
Byte size:<asp:label id="fsize" runat="server"/><br>
File type:<asp:label id="ftype" runat="server"/><br>
User account:<asp:label id="username" runat="server"/><br>
Remaining space:<asp:label id="respace" runat="server"/><br>
Used space:<asp:label id="nowspace" runat="server"/><br>
Upload status:<asp:label id="errors" runat="server"/>
</div>
*** The above tells the user the relevant information before and after the file is uploaded in the browser.
</body>
</html>
Conclusion
The method described in this article is based on component-less technology and takes into account more aspects of file security and personal privacy. It is most suitable for use on Windows Server 2003 and IIS6.0 platform. The method is simple and safe, and can be slightly expanded. , such as adding the user number and group number in userlist, and adding the group number in files, you can set the file permissions, which can facilitate network submission, verification, and sharing of files. Coupled with a disk array, data security will be qualitatively improved.