Configure FTP Server File-Conversion Actions


The FTP server can convert files during transfer to compress and uncompress files automatically. Suppose that the user is transferring a file to his Microsoft Windows machine that was TARed and GZIPed on a Linux machine. If the user does not have an archive utility installed to uncompress these files, he cannot access or use the files.

As the FTP server administrator, you can configure the FTP server to automatically unarchive these files before download, should the site support users who might not have unarchive capabilities. Additionally, you can configure an upload area for the users, and then configure the FTP server to automatically compress any files transferred to the server.

The structure of the format of the ftpconversions file is

1:2:3:4:5:6:7:8 


where 1 is the strip prefix, 2 is the strip postfix, 3 is the add-on prefix, 4 is the add-on postfix, 5 is the external command, 6 is the types, 7 is the options, and 8 is the description.

Strip Prefix

The strip prefix is one or more characters at the beginning of a filename that should be automatically removed by the server when the file is requested. By specifying a given prefix to strip in a conversions rule, such as devel, the user can request the file devel_procman.tar.gz by the command get procman.tar.gz, and the FTP server will perform any other rules that apply to that file and retrieve it from the server. Although this feature is documented, as of version 2.6.2, it has yet to be implemented.

Strip Postfix

The strip postfix works much the same as strip prefix, except one or more characters are taken from the end of the filename. Typically, this feature is used to strip the .gz extension from files that have been TARed and GZIPed when the server is performing automatic decompression before sending the file to the client.

Add-On Prefix

The add-on prefix conversion instructs the server to insert one or more characters to a filename before it is transferred to the server or client. For example, a user requests the file procman.tar.gz. The server has a conversion rule to add a prefix of gnome to all .tar.gz files; thus the server would append this string to the file before sending it to the client. The user would receive a file called gnome_procman.tar.gz. Keywords such as uppercase and lowercase can be used in this function to change the case of the filename for those operating systems in which case makes a difference. Similar to the strip prefix conversion, this feature is not yet implemented in version 2.6.2.

Add-On Postfix

An add-on postfix instructs the server to append one or more characters to the end of a filename during the transfer or reception of a file. A server can contain TARed packages of applications that are uncompressed. If an add-on postfix conversion was configured on the server, the server could compress the file, append a .gz extension after the file was compressed, and then send that file to the client. The server could also do the same action for uncompressed files sent to the server. This would have the effect of conserving disk space on the server.

External Command

The external command entries in the ftpconversions file contain the bulk of the FTP server conversion rules. The external command entry tells the server what should be done with a file after it is transferred to the server. The specified conversion utility can be any command on the server, although generally it is a compression utility. As the file is sent, the server passes the file through the external command. If the file is being uploaded to the server, the command needs to send the result to standard in, whereas a download will send the command to standard out. For example, here is an entry specifying the tar command:

:   : :.tar:/bin/tar -c -f - %s:T_REG|T_DIR:O_TAR:TAR 


The following sections describe the fields in a conversion entry.

Types

You must use the types field of the ftpconversions file to tell the server what types of files the conversion rules apply to. Separate the file type entries with the (|) character, and give each type a value of T_REG, T_ASCII, and T_DIR.

T_REG signifies a regular file, T_ASCII an ASCII file, and T_DIR a directory. A typical entry is T_REG | T_ASCII, which signifies a regular ASCII file.

Options

The options field informs the server what action is being done to the file. Similar to the types file, options are separated by the (|) character. Here are the valid ranges you can assign to items in the options field:

  • O_COMPRESS to compress the file

  • O_UNCOMPRESS to uncompress the file

  • O_TAR to tar the file

An example of this field would be O_COMPRESS | O_TAR, where files are both compressed and TARed.

Description

The description field allows an administrator to quickly understand what the rule is doing. This field does not have any syntax restriction, although it is usually a one word entrysuch as TAR, TAR+COMPRESS, or UNCOMPRESSwhich is enough to get the concept across.

An Example of Conversions in Action

Crafting complex conversion entries is a task perhaps best left to the Linux/UNIX expert, but the sample ftpconversions file included with wu-ftpd provides more than enough examples for the average administrator. Building your own simple conversion entry is not really too difficult, so let's examine and decode an example:

:.Z:  :  :/bin/compress -d -c %s:T_REG|T_ASCII:O_UNCOMPRESS:UNCOMPRESS 


In this example, the strip prefix (field 1) is null because it is not yet implemented, so this rule does not apply to prefixes. The second field of this rule contains the .Z postfix; thus it deals with files that have been compressed with the compress utility. The rule does not address the add-on prefix or postfix, so fields 3 and 4 are null. Field 5, the external command field, tells the server to run the compress utility to decompress all files that have the .Z extension, as the -d parameter signifies. The -c options tells compress to write the output of the compress utility to the standard out, which is the server in this case. The %s is the name of the file that the rule was applied against. Field 6 specifies that this file is a regular file in ASCII format. Field 7, the options field, tells the server that this command uncompresses the file. Finally, the last field is a comment that gives the administrator a quick decode of what the conversion rule is doing, that is, uncompressing the file.

Examples

Several conversion rules may be specified in wu-ftpd's default ftpconversions file. Additional examples, such as for Sun's Solaris operating system, might also be available in additional wu-ftpd documentation.




Ubuntu Unleashed
Ubuntu Unleashed 2011 Edition: Covering 10.10 and 11.04 (6th Edition)
ISBN: 0672333449
EAN: 2147483647
Year: 2006
Pages: 318

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net