Added a specific reply function for the data channel.
[uftps.git] / reply.c
blobe4b99d6dae15e19bad9304aca62e533dc740cd9f
1 /*
2 * User FTP Server, Share folders over FTP without being root.
3 * Copyright (C) 2008 Isaac Jurado
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
8 * version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "uftps.h"
24 * Send a reply to the client over the control connection. Not a complex
25 * function at all, but necessary almost everywhere else.
27 void reply (const char *str, int len)
29 int b;
31 debug("Reply : %.*s", len - 2, str);
33 do {
34 b = send(SS.control_sk, str, len, 0);
35 if (b == -1)
36 fatal("Control channel output");
38 str += b;
39 len -= b;
40 } while (len > 0);
45 * Send reply over the current data connection. It succeeds (return value 0)
46 * when all data has been transferred. It fails otherwise (return value -1),
47 * that is, either by an incomplete transfer or a system error.
49 int data_reply (const char *data, int len)
51 int b, l = 0;
53 while (l < len)
55 b = send(SS.data_sk, &data[l], len - l, 0);
56 if (b <= 0)
58 error("Sending listing data");
59 return -1;
62 l += b;
65 return 0;