fupload - A Visual FoxPro Script for Uploading Files

Systems Development

fupload is a script written in Visual FoxPro. I created fupload to make it easier to upload large numbers of PDF and ZIP files at work. It was built on the principle of “scratching your own itch.”

Since I wanted to learn how to use git and github, I decided to organize the code better and make it available as open source. This script was made for the Windows platform. Visual FoxPro must be installed on the machine. To complement the script, I use a .bat file to send the files to the server.

Those using other operating systems can take inspiration from this solution and create cross-platform alternatives.

Now, here’s the tutorial for using fupload:

  1. Download the fupload .zip file and extract it to your c:\ drive. The application is available at:

http://github.com/valeriofarias/fupload/tree

If you use git, you can clone the project with this command:

git clone git://github.com/valeriofarias/fupload.git

The figure below shows the fupload utility’s folder structure:

fupload folder structure fupload folder structure

  • backup -> (previously called historic) stores a copy of all files sent to the server
  • log -> stores log files
  • script -> the utility’s main folder. It contains the fupload.prg file, which is the main program. It also contains the .bat file.
  • start -> as the name suggests, this is where you put the files to be sent to the server. This is the first step.
  • tmp -> when a file is processed by the fupload script, it is renamed and sent to this folder. The log file used to create the HTML page is also created here.

The script is preconfigured to run on the C drive, but you can easily change the settings to run it on another drive (d:, e:). Simply change the DEFAULTFOLDER constant to the drive you want.

Note: You also need to configure the server’s destination folder. In the script, change the constants SERVERFOLDERPDF (the server path for .pdf files) and SERVERFOLDERZIP (for .zip files). The image below shows the relevant section of the fupload.prg code:

fupload configuration

fupload configuration

You also need to configure the upload.winscript file. First rename this file to upload.bat. Then open it in Notepad, change pathserver, and save the file:

@ECHO OFF
ECHO PAUSA DE SEGURANCA
PAUSE

COPY c:\fupload\tmp\*.pdf pathserver\pdf\
COPY c:\fupload\tmp\*.zip pathserver\zip\

MOVE c:\fupload\tmp\*.log c:\fupload\log\
MOVE c:\fupload\tmp\*.zip c:\fupload\backup\
MOVE c:\fupload\tmp\*.pdf c:\fupload\backup\

DEL c:\fupload\tmp\*.*

After configuring it, just put the files you want to send to the server in the start folder.

In the example below, you can see that the file names contain accents and spaces between words. This is where fupload works its magic, removing the spaces and accents:

first step: put the files in the start folder

first step: put the files in the start folder

Now you can load fupload.prg in Visual FoxPro, as shown in the image below. It works perfectly well without a parameter. The parameter is only used to add a prefix at the beginning of the file name to identify its type, such as doc, form, etc.

Loading fupload.prg in Visual FoxPro

Loading fupload.prg in Visual FoxPro

When processing is complete, the message box below appears:

Message indicating that the script has finished: Message indicating that the script has finished

Now we can open the tmp folder and see the result. Notice that all the files have been renamed, with accents and spaces removed. A prefix has also been added to the beginning; in this case, doc. A log file has also been created:

Files modified by fupload: files modified by fupload

Let’s take a look at the log file. Its name follows this pattern: “logupload_year_month_day__hour_minute_second[optional prefix]_n[number of files].txt”_. When you open the log file, it already contains the final HTML code to put on the page. If you want, you can change the link text to make it more appealing or readable. Then just copy it and put it on the HTML page.

Log file: log file

To finish, simply run the upload.bat file (shown below) in the script folder. This procedure sends the files to the server and clears the tmp folder. The .pdf and .zip files are also copied to the backup folder, just to be safe. The log file is moved to the log folder, giving you a history of recent uploads. You can delete the contents of the backup folder whenever you like.

upload.bat file: upload.bat file