Removed non portable -v flag for rm command.
[uftps.git] / send_file-generic.c
blob10b5b96783d932752f9b7b691466981870d01c04
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"
21 #ifdef __MINGW32__
22 # include "hase.h"
23 #else
24 # include <unistd.h>
25 # include <fcntl.h>
26 #endif
30 * Generic RETR command implementation.
32 void send_file (void)
34 int f, e, b = 0;
35 off_t size, completed = 0;
37 f = open_file(&size);
38 if (f == -1)
40 SS.file_offset = 0;
41 return;
44 /* Apply a possible previous REST command */
45 if (SS.file_offset > 0)
47 completed = lseek(f, SS.file_offset, SEEK_SET);
48 if (completed == -1)
50 error("Seeking file %s", SS.arg);
51 reply_c("450 Could not restart transfer.\r\n");
52 close(f);
53 return;
57 e = open_data_channel();
58 if (e == -1)
60 close(f);
61 return;
64 reply_c("150 Sending file content.\r\n");
65 #ifdef __MINGW32__
66 debug("Initial offset is %I64d", completed);
67 #else
68 debug("Initial offset is %lld", (long long) completed);
69 #endif
72 * Main transfer loop. We use the auxiliary buffer to temporarily store
73 * chunks of file.
75 while (completed < size)
77 b = read(f, SS.aux, LINE_SIZE);
78 if (b == -1)
79 break; /* Cannot show any useful error message here */
81 e = data_reply(SS.aux, b);
82 if (e == -1)
83 break;
85 completed += b;
88 if (b != -1 && e != -1)
89 reply_c("226 File content sent.\r\n");
90 else
91 reply_c("426 Something happened, transfer aborted.\r\n");
93 close(f);
94 closesocket(SS.data_sk);
95 SS.data_sk = -1;