4.6. File upload

The final task is to transfer the html files (and any other non html files) from your Website up to the server which hosts the site. Just before describing that, it may be worthwhile looking at Section 5.2. That section address related issues of Website layout and file location.

4.6.1. Uploading with ant

The section of the build.xml file which covers the upload task is shown in Example 12

Example 12. The ftp task, from build.xml

  <target name="upload" >
  <ftp server="ftp.mywebsite.com"              1
       userid="myuserid"                          2
       password="mypassword"                      3
       passive="yes"                              4
       remotedir="/server/path/to/this/website"   5
       verbose="yes"
       >
    <fileset dir="html">                       6
      <include name="**/*.html"/>              7
      <include name="graphics/*.svg"/>         8
      <include name="download/*.*"/>           9
    </fileset>
  </ftp>  
  <tstamp>
    <format property="fintim" pattern="E @ H:m a" locale="en,UK"/>
  </tstamp>
  <echo>Finished on ${fintim}</echo>        10
</target>

1

The url where your server resides.

2

Your username to get into that side

3

And the associated password

4

Passive mode may be required. It is on my site. Ask your admin help if you're unsure

5

The path, from the root of your area, where you want the files to go. All transfer targets will be relative to this point in the directory structure

6

Where to start looking for the files to upload

7

What to upload (first set of files). All files, in the html directory and all sub-directories, with an 'html' extension.

8

And all the svg files in the graphics directory

9

And all files, regardless of name, in the download directory

10

Tell me when I've finished! Just the time and this message


An important point to note in this script. It makes use of directory based tasks, which is commonly used throughout ant to identify files and directories for reading and writing. If you wish to be selective in what you upload, it will pay dividends to read this section and use it the fileset section of the ant upload task.

The example above selects all the html files in the html directory; all the scalable vector graphics files in the html/graphics directory and everything in the download directory. There is a similar directive to exclude named files or groups of files!

Once again the task may be selected individually from the command line (yet again assuming you have not specified a depends attribute on the target element. The command is

  >ant upload

Until you are confident that you have all the parameters right, watch the output of the task to see what is happening. Any errors will be reported. You should be able to see the changed files (or added ones) once this task is complete