source: src/router/proftpd/doc/contrib/ftpmail.html @ 12685

Last change on this file since 12685 was 12685, checked in by BrainSlayer, 4 years ago

new version

File size: 7.4 KB
Line 
1<!-- $Id: ftpmail.html,v 1.2 2008/08/18 20:50:51 castaglia Exp $ -->
2<!-- $Source: /cvsroot/proftp/proftpd/doc/contrib/ftpmail.html,v $ -->
3
4<html>
5<head>
6<title>ftpmail: Automated Email Notifications of Uploads</title>
7</head>
8
9<body bgcolor=white>
10
11<hr>
12<center>
13<h2><b><code>ftpmail</code>: Automated Email Notifications of Uploads</b></h2>
14</center>
15<hr><br>
16
17<p>
18The <code>ftpmail</code> program is a Perl script designed to read
19ProFTPD's <code>TransferLog</code> log entries, watching for uploads, and
20to send an automatic email notification when uploads occur.  To use
21<code>ftpmail</code>, you configure your <code>proftpd</code> daemon to
22write its <code>TransferLog</code> to a <a href="http://www.proftpd.org/docs/howto/Logging.html#FIFOs">FIFO</a>; the <code>ftpmail</code> program is a FIFO
23reading program which then processes those log messages.
24
25<p>
26The most current version of <code>ftpmail</code> is distributed with the
27ProFTPD source code.
28
29<h2>Author</h2>
30<p>
31Please contact TJ Saunders &lt;tj <i>at</i> castaglia.org&gt; with any
32questions, concerns, or suggestions regarding this program.
33
34<p>
35<hr><br>
36<h2><a name="Usage">Usage</a></h2>
37First, you have the following Perl modules installed:
38<ul>
39  <li>Mail::Sendmail
40  <li>Time::HiRes
41</ul>
42You can easily determine if your Perl has these modules present, using:
43<pre>
44  # perl -MMail::Sendmail -e0
45  # perl -MTime::HiRes -e0
46</pre>
47If you see an error similar to:
48<pre>
49  Can't location Mail/Sendmail.pm in @INC (@INC contains: <i>...</i>)
50</pre>
51it means that you do not have that Perl module installed.  Go to <a href="http://search.cpan.org">search.cpan.org</a> to download the latest versions of
52these modules, and install them as per their instructions.
53
54<p>
55Next, you need to create the FIFO that <code>ftpmail</code> will read from.
56See the <code>mkfifo(1)</code> man page for instructions on how to create
57a FIFO.  Note that you <b>must</b> use <code>mkfifo</code> to create a FIFO;
58using an ordinary file that happens to have a ".fifo" extension will not work
59for this.
60
61<p>
62After that, you need to start <code>ftpmail</code> running, <i>before</i>
63starting <code>proftpd</code>.  For example, you might do:
64<pre>
65   # ./ftpmail \
66       --fifo=/var/proftpd/log/transfer.fifo \
67       --from='tj@castaglia.org' \
68       --recipient='tj@castaglia.org' \
69       --smtp-server=mail.domain.com \
70       --attach-file \
71       --log=/var/proftpd/log/transfer.log &
72</pre>
73The key is to make <code>ftpmail</code> run in the background, so that it is
74constantly running.  If the <code>ftpmail</code> process dies, then
75<code>proftpd</code> will not be able to write the <code>TransferLog</code>.
76
77<p>
78The next step is to configure your <code>proftpd</code> daemon to write to
79the FIFO you created.  Thus in your <code>proftpd.conf</code>, you would
80use the same path as given to <code>ftpmail</code>'s <code>--fifo</code>
81option, <i>e.g.</i>:
82<pre>
83  TransferLog /var/proftpd/log/transfer.fifo
84</pre>
85 
86<p>
87Then start <code>proftpd</code>, log in, upload a file, and see what happens.
88One user modified their <code>init</code> for <code>proftpd</code> such
89that the <code>ftpmail</code> program was automatically started before
90the <code>proftpd</code> daemon was started.
91
92<p>
93<b>Options</b><br>
94The following shows the full list of <code>ftpmail<code> options; this
95can also be obtained by running:
96<pre>
97  # ftpmail --help
98
99  usage: ftpmail [--help] [--fifo $path] [--from $addr] [--log $path]
100    [--recipient $addr] [--subject $string] [--smtp-server $addr]
101    [--attach-file] [--ignore-users $regex | --watch-users $regex]
102
103  The purpose of this script is to monitor the TransferLog written by proftpd
104  for uploaded files.  Whenever a file is uploaded by a user, an email
105  will be sent to the specified recipients.  In the email there will be
106  the timestamp, the name of the user who uploaded the file, the path to
107  the uploaded file, the size of the uploaded file, and the time it took
108  to upload.
109
110  Command-line options:
111
112    --attach-file         If used, this will cause a copy of the uploaded file
113                          to be included, as an attachment, in the generated
114                          email.
115
116    --fifo $path          Indicates the path to the FIFO to which proftpd is
117                          writing its TransferLog.  That is, this is the path
118                          that you used for the TransferLog directive in your
119                          proftpd.conf.  This parameter is REQUIRED.
120
121    --from $addr          Specifies the email address to use in the From header.
122                          This parameter is REQUIRED.
123
124    --help                Displays this message.
125
126    --ignore-users $regex Specifies a Perl regular expression.  If the
127                          uploading user name matches this regular expression,
128                          then an email notification is NOT sent; otherwise,
129                          an email is sent.
130
131    --log $path           Since this script reads the TransferLog using FIFOs,
132                          the actual TransferLog file is not written by default.
133                          Use this option to write the normal TransferLog file,
134                          in addition to watching for uploads.
135
136    --recipient $addr     Specifies an email address to which to send an email
137                          notification of the upload.  This option can be
138                          used multiple times to specify multiple recipients.
139                          AT LEAST ONE recipient is REQUIRED.
140
141    --smtp-server $addr   Specifies the SMTP server to which to send the email.
142                          This parameter is REQUIRED.
143
144    --subject $string     Specify a custom Subject header for the email sent.
145                          The default Subject is:
146
147                            User '$user' uploaded file '$file' via FTP
148
149    --watch-users $regex  Specifies a Perl regular expression.  If the
150                          uploading user name matches this regular expression,
151                          then an email notification is sent; otherwise,
152                          no email is sent.
153</pre>
154
155<p><a name="FAQ"></a>
156<b>FAQ</b><br>
157
158<p>
159<font color=red>Question</font>: I would like to use <code>ftpmail</code>
160to send emails, but only for files uploaded to specific domains.  How do
161I do this?<br>
162<font color=blue>Answer</font>: To do this, you will need to configure
163different <code>TransferLog</code> files in your different
164<code>&lt;VirtualHost&gt;</code> sections in your <code>proftpd.conf</code>.
165
166<p>
167The TransferLog file format does not include a field indicating the IP
168address (or DNS name) of the server on which the file transfer is occurring.
169This means that <code>ftpmail</code> does not know which server is handling
170the transfer.  So, in order to have <code>ftpmail</code> send emails only
171for certain domains/servers, you will have to do something like:
172<pre>
173 &lt;VirtualHost a.b.c.d&gt;
174    ...
175    TransferLog /path/to/vhost1.xferlog
176    ..
177  &lt;/VirtualHost&gt;
178
179  &lt;VirtualHost e.f.g.h&gt;
180    ...
181    TransferLog /path/to/vhost2.xferlog
182    ...
183  &lt;/VirtualHost&gt;
184</pre>
185Then start instances of <code>ftpmail</code> running, but only for the
186<code>TransferLog</code> files of the domains/virtual servers to be monitored.
187
188<p>
189<hr><br>
190
191Author: <i>$Author: castaglia $</i><br>
192Last Updated: <i>$Date: 2008/08/18 20:50:51 $</i><br>
193
194<br><hr>
195
196<font size=2><b><i>
197&copy; Copyright 2008 TJ Saunders<br>
198 All Rights Reserved<br>
199</i></b></font>
200
201<hr><br>
202
203</body>
204</html>
Note: See TracBrowser for help on using the repository browser.