Over the past few years, creating and maintaining sophisticated Web sites has become easier and easier. Many hypertext markup language (HTML) editors make the job a breeze. Most Web sites are created on PCs and transferred to Web serversa simple task for UNIX and PC-based Hypertext Transfer Protocol (HTTP) servers. Unfortunately, it is not so easy to transfer a PC-created Web site to an AS/400-based Web server.
First, the degree of knowledge required to update an AS/400-hosted Web site is greater than for sites hosted on UNIX or NT servers. The Web author requires specialized knowledge of AS/400 commands to change user authorities to files and directories. This also introduces some security issues, because the site administrator has to give the Web author a level of access that goes beyond changing content.
Second, the current process of updating an AS/400-hosted Web site can be time- consuming and prone to errors. Once a Web site is created on a PC, the content must be placed on an AS/400 HTTP server. The Web author must log into the server via FTP, transfer each file, create subdirectories, remove public authority for each transferred object, and add *RX authority for the QTMHHTTP user profile for each object. All this increases the potential of introducing errors into the Web site during updates.
The FTPMirror utility provided here removes these obstacles by creating an effortless way to maintain and update your AS/400 Web site. In many cases, the FTPMirror process makes updating your AS/400 server easier and faster than updating a UNIX or PC server. FTPMirror takes full responsibility for updating a Web site, and it does the job efficiently and seamlessly. The author is freed from the hassle of logging into the server via FTP, transferring each file individually, creating subdirectories, and setting the appropriate user profile attributes. Web authors can focus their time and energy on what they do best: creating Web sites.
The Functions of FTPMirror
The FTPMirror utility performs five functions when updating a Web site:
1. Logs on to the AS/400 via FTP. FTPMirror updates a Web site by first logging on to the AS/400 via an FTP login name and password supplied during the configuration process.
2. Optionally deletes any existing content. Next, FTPMirror determines if the destination files and directories should be deleted prior to sending the new content (this is an optional feature specified during the FTPMirror configuration process).
3. Transfers content to the AS/400. Each file and directory is then transferred to the AS/400 exactly as it is on the PC. Depending on the settings chosen during FTPMirror configuration, the file and directory names are either retained exactly or converted to upper- or lowercase. (The user specifies the case setting during the FTPMirror configuration process.)
4. Makes required authority changes. After each file and directory is transferred, FTPMirror automatically makes the appropriate authority changes.
5. Logs off of the server. FTPMirror logs off the AS/400 FTP server as soon as the transfer is complete.
Setup and Configuration
FTPMirror runs under Windows 95/NT and is the FTP client that transfers the Web application from the PC to the AS/400. To get your copy of FTPMirror, access Midrange Computings Web site at http://www.midrangecomputing.com/mc/prog or visit the Information Exchange Systems Web site at http://www.in-exs.com/.
Once downloaded, run FTPMirror.EXE. The setup program will guide you through the setup process.
After the setup process is complete, you must configure FTPMirror. Open the application by selecting FTPMirror from Start/Programs. You will be presented with an informational dialog informing you that FTPMirror must be configured before it is used. Click on the OK button, and the configuration dialog will appear (see Figure 1). The setup screen consists of two tabs: Directory and Server. The Directory tab configures the source and destination directories. This tab also allows you to specify the case (upper or lower or do not change) and whether the destination files should be removed prior to transfer. Figure 1 illustrates a configuration in which source directory is c: emp and destination directory is /as400web. The Server tab allows you to specify the FTP server, login name, and password. The server entry may be entered as either an IP address or a domain name. The login name must be a valid FTP account with appropriate access for the specified server. When you complete the configuration and click on the OK button, the main FTPUtility dialog appears as illustrated in Figure 2.
Any attempt to access the setup screen after the initial setup and configuration process is complete requires the user to enter a login name and password. The login name and password is the same as the FTP login name and password specified in the server tab. As an added security feature, FTPMirrors configuration files are encrypted, making it almost impossible for unauthorized users to view the login name.
The Code That Makes FTPMirror Work
FTPMirror was created using Visual Basic (VB) Version 5.0. In addition to VB5, an ActiveX control from Mabry Software (http://www.mabry.com) provides FTP functionality. Microsoft produces a free FTP ActiveX control, but it lacks the ability to send commands to the server. FTPMirror requires that AS/400-specific commands be sent from the PC for each file transferred to set up proper authorities. (*PUBLIC authority is changed to *EXCLUDE, and *RX authority given to the QTMHHTTP profile.) The Mabry ActiveX control is the only one I found that provides the ability to send commands to the server.
After you click the Mirror Directory button from the main dialog (see Figure 2), the application logs into the AS/400 using the login name, password, and host supplied in the setup screen. The FTP ActiveX control logs the user into the AS/400 by setting the properties LogonName, LogonPassword, and Host, and executing the Connect method (see Figure 3).
FTPMirror can optionally remove any existing content on the AS/400. The content is removed after login and prior to transferring the PC content to the AS/400. To remove a directory, the CleanDestinationDirectory subroutine is called, with the destination path as a parameter. This subroutine starts at the destination directory and removes all files and subdirectories (see Figure 4), calling itself recursively until all subdirectories have been cleaned.
To perform this operation, the subroutine must first obtain a listing of the files in the directory you passed as a parameter. This is accomplished using the GetFileList method of the FTP ActiveX control. The files are stored in a module level array named sDirList. This array holds all files and subdirectories found in the directory passed as a parameter. After the list of files and directories has been retrieved, the list is stored in an array that is local to the CleanDestinationDirectory subroutine, and the contents of module level sDirList array are cleared. The reason for storing the contents at the procedure level is to allow the CleanDestinationDirectory subroutine to be called recursively for each subdirectory contained within the array. For each element in the local array of files and directories, the ChangeDir method of the ActiveX control is executed. If the element in the array is a directory, the CleanDestinationDirectory is called again and the procedure starts over. If the element is a file, a trappable error occurs and the file is removed with the Delete method of the ActiveX control. Any subdirectories of the destination directory are removed with a method call to DeleteDir of the ActiveX control.
With the DoTheTransfer function (see Figure 5), FTPMirror transfers each file and directory to the server, starting with the source directory. Each is transferred in either ASCII or binary mode. (FTPMirror makes a determination for each file, based on the file extension. This functionality is in the code and can be modified to include additional file formats. Currently, all files are transferred as binary except for .htm, HTML, and .txt files. Additional files can be transferred as ASCII by modifying the SetFileType function.) For each file and directory, public authority is removed and *RX access is added to the QTMHHTTP user profile. DoTheTransfer is called for each subdirectory to clear its content.
Once the transfer is complete, one line of code disconnects the FTP server. The Disconnect method of the FTP ActiveX control performs a normal logoff from the AS/400 FTP server.
During the setup and configuration of FTPMirror, sensitive information is entered and stored permanently within the application. However, there is no reason to be concerned about security, because FTPMirror protects all user information by encrypting all files in the INI file. Encrypted information is difficult to read or modify.
Throughout the transfer process, FTPMirror provides the end user with visual feedback on the transfer status (see Figure 6). The feedback displays total number of files to be transferred and the name and size of the file currently being transferred. The display also consists of a current file status bar and an overall status bar to enable the user to monitor file transfer progress. The FTP ActiveX control provides four different events for displaying user feedback: Connected, DirItem, Progress, and Done. Detailed descriptions of these events fall outside the scope of this article, but you can view the source code or refer to the FTP ActiveX controls help file for additional information.
Adding More Power
While FTPMirror provides a fast and efficient way to update an AS/400-based Web site, this utility has the potential to create an even- more-powerful tool that will fit individual needs. If you think additional features would make FTPMirror a better utility, please feel free to download the source and add your ideas.
One feature that would enhance the functionality of FTPMirror would be the ability to update multiple sites. Multiple profiles could be incorporated into FTPMirror by storing information for multiple Web sites in the INI file. The end user would then select which Web site to update.
Another feature that could make FTPMirror even more exciting would be command line operation. This would allow for batch processing of Web updates. The environment variable COMMAND$ could be read in by the Sub Main procedure to determine the correct action to take.
Both the multiple profiles and command line arguments could be used together to provide a versatile tool for updating AS/400 Web sites.
For both the AS/400 administrator and the Web author, FTPMirror is a much easier method for maintaining and updating an AS/400-based Web site than the traditional method is. It reduces the workload and provides a solid foundation upon which you can build sophisticated Web sites.
|
Private Sub LogUserOn ()
Dim objcfg As New FTPMirror.FTPMirrorConfig
With mFTP1
If .State = FTP_DISCONNECTED Then
StatusBar1.Panels(state) = Connecting to FTP server...
.Host = objcfg.Server
. LogonName = objcfg.User
. LogonPassword = objcfg.Pwd
.Connect
End If
End With
End Sub Private Sub CleanDestinationDirectory( sPath As String)
Dim cfg As New FTPMirror.FTPMirrorConfig
Dim sTempDirList As Variant temp copy of directory listing to work with - this contains a
string array retrieved from the DirItem event
Dim iIndex As Integer
On Error GoTo CleanItErr
If mbCancel Then Exit Sub
On Error Resume Next
mFTP1.GetFilenameList obtain a listing of files... this will be saved in an array
On Error GoTo CleanItErr
ReDim sTemDirList( UBound(sDirList)) redim a local copy of the array
sTempDirList = sDirList store the module level copy to a local copy
ReDim sDirList(0) reset module level file list.
show the user we are cleaning the destination
StatusBar1.Panels(state) = Cleaning destination files and directories
loop through each found directory and file
For iIndex = LBound(sTempDirList) To UBound(sTempDirList)
If mbCancel Then Exit Sub check if we should the cancel button has been pressed
If Trim$(sTempDirList(iIndex)) .. And Trim$(sTempDirList(iIndex)) . And Trim$(sTempDirList(iIndex))
Then
force a change to the directory. This will produce a trappable error if it is a file.
If it is a file we will delete it. If the directory change works we will call this
sub again, passing the new path as a parameter.
mFTP1.ChangeDir KillReturns(sTempDirList(iIndex))
the changedir worked so this is a directory.... call this sub again.
CleanDestinationDirectory sPath & (sTempDirList(iIndex))
StatusBar1.Panels(state) = Cleaning directory & sPath & (sTempDirList(iIndex))
mFTP1.ChangeDir sPath
mFTP1.DeleteDir KillReturns(sTempDirList(iIndex))
End If
resumehere: stupid goto
Next iIndex
Exit Sub
CleanItErr:
Select Case Err.Number
Case 20550
this is a file not a directory so lets delete it
StatusBar1.Panels(state) = Cleaning file & sPath & ( sTempDirList( iIndex))
mFTP1.Delete KillReturns( sTempDirList( iIndex))
Resume resumehere
Case Else
MsgBox Err.Number & : & Err.Description, vbInformation, MSGBOX_HEADING
End Select
End Sub Private Function DoTheTransfer (sSourcePath As String, sDestinationPath As String) As Integer
Dim File_Name As String name of the PC file to transfer
Dim File_Path As String source path of the PC
Dim File_Read As Integer
Dim X As Boolean
Dim i As Integer
Dim StrtPath As String
Dim cfg As New FTPMirror.FTPMirrorConfig
On Error GoTo DoTheTransferErr
mFTP1.ChangeDir sDestinationPath change to the destination directory
If mbCancel Then Exit Function exit if cancel pressed
File_Path = sSourcePath &
File_Name = SetCase( Dir$(File_Path, vbDirectory))
File_Read = 1
X = False
Do While File_Name
If File_Name . And File_Name .. Then
not a directory so copy file to Server..
Figure 3: The LogUserOn routine retrieves information from the FTPMirror.INI file
Figure 4: The CleanDestinationDirectory routine cleans the content on the server, starting at the destination directory
If GetAttr( File_Path & File_Name) vbDirectory Then
mFTP1.ChangeDir sDestinationPath
set the max value of the progress bar to the file size
If FileLen( File_Path & File_Name) > 0 Then
progBar(PROGRESS_THIS_FILE).Max = FileLen(File_Path & File_Name)
Else
progBar(PROGRESS_THIS_FILE).Max = 1
End If
show the use what file is being transferred
StatusBar1.Panels(state) = Copying file & File_Name & to server ( &
Format$(FileLen(File_Path & File_Name), #,###) & bytes) mFTP1.Type = SetFileType( File_Path & File_Name) set the transfer mode (binary or ascii)
mFTP1.PutFile File_Path & File_Name, File_Name copy the file to the server
increment the overall file count
progBar(PROGRESS_OVERALL).Value = progBar(PROGRESS_OVERALL).Value + 1
StatusBar1.Panels( filenofn) = File & progBar(PROGRESS_OVERALL).Value + 1 & of &
progBar(PROGRESS_OVERALL).Max
change security on destination file
StatusBar1.Panels(state) = Changing Security for & File_Name
mFTP1.Write rcmd CHGAUT OBJ( & sDestinationPath & File_Name & ) USER(*PUBLIC)
DTAAUT(*EXCLUDE) & vbCrLf mFTP1.Read
mFTP1.Write rcmd CHGAUT OBJ( & sDestinationPath & File_Name & ) USER(QTMHHTTP) DTAAUT(*RX) &
vbCrLf
mFTP1.Read
If mbCancel Then Exit Function
Else this is a directory... lets do some recursion
StrtPath = File_Path & File_Name
X = True
If Not Trim$(StrtPath) = Then
CreateDestinationDirectory ( GetDIr(StrtPath)), sDestinationPath
sent rcmd to 400. Remove public access... add *RX to QTMHHTTP profile
StatusBar1.Panels(state) = Changing Security for & File_Name
mFTP1.Write rcmd CHGAUT OBJ( & sDestinationPath & File_Name & ) USER(*PUBLIC)
DTAAUT(*EXCLUDE) & vbCrLf mFTP1.Read
mFTP1.Write rcmd CHGAUT OBJ( & sDestinationPath & File_Name & ) USER(QTMHHTTP) DTAAUT(*RX)
& vbCrLf
mFTP1.Read
DoTheTransfer StrtPath, sDestinationPath & GetDIr(StrtPath) & /
End If
End If
End If
If X = True Then
File_Name = SetCase(Dir$(File_Path, vbDirectory))
For i = 2 To File_Read
File_Name = SetCase(Dir$)
Next
X = False
End If
File_Name = SetCase(Dir$)
File_Read = File_Read + 1
If mbCancel Then Exit Function
Loop
Exit Function
DoTheTransferErr:
MsgBox Err.Number & : & Err.Description, vbInformation, MSGBOX_HEADING
End Function
LATEST COMMENTS
MC Press Online