Home > database >  Automatic update to download the files in several methods in the system
Automatic update to download the files in several methods in the system

Time:10-04

The introduction



With the rapid development of information technology, all kinds of large-scale application system has become a modern enterprise (matter) industry the necessary tools, client/server (C/S) structure of the operating mode with good stability, high safety, fast and other characteristics are widely used in various kinds of application system, in the application system based on C/S mode, the client program upgrade is an unavoidable problem, the traditional manual upgrade workload big, unreliable, automatic update function for the maintenance of the whole system is of great significance,

In the automatic upgrade system, download files is the most important and the most complex one step, depending on the upgrade file storage, can adopt different methods will need to upgrade file downloaded to the client, realize the upgrade,

Original concept as a visual object oriented rapid development tools, by most developers for the development of C/S mode system, this paper discusses the implementation methods in the original concept environment, but these methods are also applicable to other development language, the versatility,



The principle of automatically update 1



The principle of different software automatic update are similar, first of all, the client program is running, get the latest version of the software of information in the server database, comparing with current versions of the client program information, if both are identical with the current system is the latest version, the version number is greater than the client if the server version number, the system will automatically call update, automatic update to close client program, and then download the latest file from the file server or database, and cover the old files, to realize automatic software upgrades,



2 files



To achieve file downloads, you must first will upgrade file stored in a specific location, according to the different methods of file storage, there are different ways to download, this article only discuss the storage and uncompressed file download,

2.1 the Shared folder

Other users on the network can use the folder called Shared folder on another computer, the Shared folder is within the scope of local area network to realize resource sharing of commonly used way, Shared folder is very easy to set up and manage the upgrade file stored in the Shared folder, can provide users to store and access upgrade file with a centralized location, maintenance workload is small, but the safety of the Shared folder is low,

2.2 the FTP server

File Transfer protocol (FTP refers to the File Transfer Protocal), namely the FTP protocol, is a special network protocol used to Transfer files, in a nutshell, support FTP server is the FTP server, FTP server generally established by a certain FTP server program, this program can not only manage the File server, the user can log in the server management, upgrade File stored in the FTP server, security can be guaranteed, but the need to establish and maintain server related professional knowledge and skills,

2.3 database

Due to the special data types in the modern relational database (for example, the types of image data in SQL SERVER 2000) the format of the file in binary stream can be stored in a database, so that you can set up a store in the database upgrade file table, record the data file, modified time, the information such as the version number, and then through the uploader will upgrade file is written to the database, using database storage upgrade file, the file in binary form deposit was not influenced by the virus and the disturbance of human factors; But in management upgrade file need to separate write file upload program, if the upgrade file is more, will also affect the response speed of the database server,



3 download file



3.1 the batch file

Batch file is also called the batch program, it is a text file contains a number of DOS commands, extension. BAT, the batch file is an executable program, execute the batch file, the file in a series of commands will automatically perform in sequence, using DOS extension command "XCOPY" can specify the location of the file is copied to the client,

Create a batch file, named upgrade. Bat, type the following command in the file:

Xcopy \ \ 192.168.2.7 \ upfile \ *. */s/y

192.168.2.7 computer IP address is stored upgrade file, upfile is the Shared folders on the computer, parameter "/s" said copies directories and subdirectories, said "/y" disabling tooltips to rewrite an existing object file, execute the script in the program of automatic update:

The run (" upgrade. Bat ")

Files in a Shared folder can be copied to the batch file directory, the advantage of this method is simple, easy to achieve convenient; Defect is clear, is a batch program is running, will open a DOS window, make the interface is not harmonious; The second is unable to determine whether the data transfer success; 3 it is usually only within the scope of the local area network (LAN),

3.2 mapping a network drive

In program development, in order to use the resources in the Shared folder, you can use the way of mapping a network drive, mapping a network drive is to other machines on the network Shared folder mapping into their machines on a disk, so that we can improve the access time,

In Windows98 operating system, for example, declaration and after call API function, can build the network mapped drives, and then you can copy need to upgrade file from the Shared folder, the following is the realization of the script (including variable as_source address to a network drive, as_copy is copying files destination address) :

//declare network mapping function

The FUNCTION ulong WNetAddConnection (ref string lpszNetPath, ref string lpszPassword, ref string lpszLocalName) LIBRARY "MPR. DLL" ALIAS FOR "WNetAddConnectionA
"
Long ll_loops, ll_i//file number, cycle times, loop variable

Long ll_flen ll_bytes_read, ll_new_pos//file length, number of bytes read files, file a new location

Blob lblb_file//copy the file

Long ll_filenum li_file_copy//handle to copy the file

//get the length of the file, and open the file

Ll_flen=FileLength (as_source)

Ll_FileNum=FileOpen (as_source StreamMode! , Read! , SHARED! )

//determine the number of read the file

IF ll_flen & gt; THEN 32765

IF the Mod (ll_flen, 32765)=0 THEN

Ll_loops=ll_flen/32765

The ELSE

Ll_loops=(ll_flen/32765) + 1

END the IF

The ELSE

Ll_loops=1

END the IF

//read the file

Ll_new_pos=1

Li_file_copy=FileOpen (as_copy StreamMode! The Write! , LockWrite! , Append!)

//copy the file

FOR ll_i=1 TO ll_loops

Ll_bytes_read=FileRead (ll_FileNum lblb_file)

FileWrite (li_file_copy lblb_file)

NEXT

//close the file

FileClose (ll_FileNum)

FileClose (li_file_copy)

Advantage: the file download speed, download process can be controlled; Disadvantages: in general can only be used within the scope of local area network (LAN), and programming needs to call API function,

3.3 the FTP control

When upgrade file stored on the FTP server, can only use the FTP function implementation file to download, because PowerBuilder8.0 itself does not provide any FTP functions, thus to realize FTP transmission, can only be applied outside the original concept of resources, Mabry Internet FTP/X Control is developing a common FTP controls, this Control is provided by Mabry Software company, it can do most of the FTP function, and can easily Control program running in the programming,

Registered after the control, you can join in the program a OLE, the control named ole_ftp, property Settings such as table 1:

Table 1 FTP controls attribute set

Attribute
Set the
Description

The Host
192.168.2.8
The FTP server address

LogonName
The user
Login name

LogonPassword
12345
Login password

The Timeout
10
Set the timeout


File download script:

//connect to FTP server

Ole_1. Object. Connect (" user ", "12345", "")

//will be the main program newver directory in the FTP server download file to the current directory

Ole_ftp. Object. Getfile (" \ newver \ main exe ", "\ main exe")

Download this way which can be realized in the local area network (LAN) can also be implemented in the Internet, and file transfer speed is fast, only need to use OLE during development, OCX and other advanced technology, and reference FTP control will increase the cost of development,

3.4 SQL statement

When upgrade file stored in the database, they can only use the SQL statement for file downloads, SQL full name is "Structured Query Language (SQL (Structured Query Language)", has been identified as a relational database SQL Language system of international standards, adopted by most of the commercial relational database system, the original concept provides a complete set of embedded SQL statements, using embedded SQL statements, can be flexibly in the program database operation, using SQL statements "SELECTBLOB" can be read from the database upgrade file:

SELECTBLOB file_data INTO: lb_file

The FROM t_upgradefile

WHERE file_name=: ls_filename;

Then use data to disk file read and write functions will file, complete the files downloaded from the database,

Use SQL statements to download files can be monitored file download progress, but the code quantity is big, complex, and download files, will increase the load of the database server, affect the response speed of the server,



4 conclusion



Automatic upgrade system implementation file download, using the above any kind of method can not only realize the individual modules in the system upgrade, also can realize the whole application system version upgrade, the above all kinds of method has been applied in the actual system and inspection, has strong practical value,
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related