Thu, Jun
4 New Articles

Facilitate AS/400 Web Site Maintenance with the FTPMirror Utility

  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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 servers—a 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 Computing’s 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, FTPMirror’s 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 control’s 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.

Figure 1: The FTPMirror setup screen

Facilitate_AS-400_Web_Site_Maintenance_with04-00.png 760x558

Private Sub LogUserOn ()

Dim objcfg As New FTPMirror.FTPMirrorConfig

With mFTP1


StatusBar1.Panels(“state”) = “Connecting to FTP server...”

.Host = objcfg.Server

. LogonName = objcfg.User

. LogonPassword = objcfg.Pwd


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

Select Case Err.Number

Case 20550

‘ this is a file not a directory so let’s 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)



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 “ &

‘ change security on destination file

StatusBar1.Panels(“state”) = “Changing Security for “ & File_Name

mFTP1.Write “rcmd CHGAUT OBJ(‘“ & sDestinationPath & File_Name & “‘) USER(*PUBLIC)

mFTP1.Write “rcmd CHGAUT OBJ(‘“ & sDestinationPath & File_Name & “‘) USER(QTMHHTTP) DTAAUT(*RX)” &


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)

mFTP1.Write “ rcmd CHGAUT OBJ(‘“ & sDestinationPath & File_Name & “‘) USER(QTMHHTTP) DTAAUT(*RX)”
& vbCrLf


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$)


X = False

End If

File_Name = SetCase(Dir$)

File_Read = File_Read + 1

If mbCancel Then Exit Function


Exit Function

MsgBox Err.Number & “: “ & Err.Description, vbInformation, MSGBOX_HEADING
End Function

Figure 5: This routine does most of the transfer work



Support MC Press Online

$0.00 Raised:

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: