Mercurial > octave-nkf
annotate src/DLD-FUNCTIONS/urlwrite.cc @ 13978:a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Fri, 02 Dec 2011 18:50:56 -0500 |
parents | 27e5f0e79f19 |
children | 43cc49c7abd1 |
rev | line source |
---|---|
6043 | 1 // urlwrite and urlread, a curl front-end for octave |
2 /* | |
3 | |
11523 | 4 Copyright (C) 2006-2011 Alexander Barth |
9880 | 5 Copyright (C) 2009 David Bateman |
6043 | 6 |
7 This file is part of Octave. | |
8 | |
9 Octave is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
7016 | 11 Free Software Foundation; either version 3 of the License, or (at your |
12 option) any later version. | |
6043 | 13 |
14 Octave is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
7016 | 20 along with Octave; see the file COPYING. If not, see |
21 <http://www.gnu.org/licenses/>. | |
6043 | 22 |
23 */ | |
24 | |
25 // Author: Alexander Barth <abarth@marine.usf.edu> | |
26 // Adapted-By: jwe | |
27 | |
28 #ifdef HAVE_CONFIG_H | |
29 #include <config.h> | |
30 #endif | |
31 | |
32 #include <string> | |
33 #include <fstream> | |
34 #include <iomanip> | |
9880 | 35 #include <iostream> |
6043 | 36 |
9880 | 37 #include "dir-ops.h" |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
38 #include "file-ops.h" |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
39 #include "file-stat.h" |
6043 | 40 #include "oct-env.h" |
9880 | 41 #include "glob-match.h" |
6043 | 42 |
43 #include "defun-dld.h" | |
44 #include "error.h" | |
45 #include "oct-obj.h" | |
46 #include "ov-cell.h" | |
47 #include "pager.h" | |
9880 | 48 #include "oct-map.h" |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
49 #include "unwind-prot.h" |
6043 | 50 |
9905
84a7c11ff928
Correctly compile even when libcurl is not present according to configure
Rik <rdrider0-list@yahoo.com>
parents:
9885
diff
changeset
|
51 #ifdef HAVE_CURL |
6043 | 52 |
53 #include <curl/curl.h> | |
9885 | 54 #include <curl/curlver.h> |
6043 | 55 #include <curl/easy.h> |
56 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
57 static int |
6043 | 58 write_data (void *buffer, size_t size, size_t nmemb, void *streamp) |
59 { | |
60 std::ostream& stream = *(static_cast<std::ostream*> (streamp)); | |
61 stream.write (static_cast<const char*> (buffer), size*nmemb); | |
62 return (stream.fail () ? 0 : size * nmemb); | |
63 } | |
64 | |
9880 | 65 static int |
66 read_data (void *buffer, size_t size, size_t nmemb, void *streamp) | |
6043 | 67 { |
9880 | 68 std::istream& stream = *(static_cast<std::istream*> (streamp)); |
69 stream.read (static_cast<char*> (buffer), size*nmemb); | |
70 if (stream.eof ()) | |
71 return stream.gcount (); | |
72 else | |
73 return (stream.fail () ? 0 : size * nmemb); | |
6043 | 74 } |
75 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
76 static size_t |
9880 | 77 throw_away (void *, size_t size, size_t nmemb, void *) |
6992 | 78 { |
9880 | 79 return static_cast<size_t>(size * nmemb); |
6992 | 80 } |
81 | |
9880 | 82 class |
83 curl_handle | |
6043 | 84 { |
9880 | 85 private: |
86 class | |
87 curl_handle_rep | |
88 { | |
89 public: | |
90 curl_handle_rep (void) : count (1), valid (true), ascii (false) | |
91 { | |
92 curl = curl_easy_init (); | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
93 if (!curl) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
94 error ("can not create curl handle"); |
9880 | 95 } |
96 | |
97 ~curl_handle_rep (void) | |
98 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
99 if (curl) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
100 curl_easy_cleanup (curl); |
9880 | 101 } |
102 | |
103 bool is_valid (void) const | |
104 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
105 return valid; |
9880 | 106 } |
107 | |
108 bool perform (bool curlerror) const | |
109 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
110 bool retval = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
111 if (!error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
112 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
113 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
6043 | 114 |
12963
27e5f0e79f19
Return better error codes from curl, even if connection is successful
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12782
diff
changeset
|
115 errnum = curl_easy_perform (curl); |
27e5f0e79f19
Return better error codes from curl, even if connection is successful
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12782
diff
changeset
|
116 if (errnum != CURLE_OK) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
117 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
118 if (curlerror) |
12963
27e5f0e79f19
Return better error codes from curl, even if connection is successful
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12782
diff
changeset
|
119 error ("%s", curl_easy_strerror (errnum)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
120 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
121 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
122 retval = true; |
9880 | 123 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
124 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
125 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
126 return retval; |
9880 | 127 } |
6043 | 128 |
9880 | 129 CURL* handle (void) const |
130 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
131 return curl; |
9880 | 132 } |
133 | |
134 bool is_ascii (void) const | |
135 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
136 return ascii; |
9880 | 137 } |
138 | |
139 bool is_binary (void) const | |
140 { | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
141 return !ascii; |
9880 | 142 } |
143 | |
144 size_t count; | |
145 std::string host; | |
146 bool valid; | |
147 bool ascii; | |
12963
27e5f0e79f19
Return better error codes from curl, even if connection is successful
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12782
diff
changeset
|
148 mutable CURLcode errnum; |
9880 | 149 |
150 private: | |
151 CURL *curl; | |
6043 | 152 |
9880 | 153 // No copying! |
154 | |
155 curl_handle_rep (const curl_handle_rep& ov); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
156 |
9880 | 157 curl_handle_rep& operator = (const curl_handle_rep&); |
158 }; | |
159 | |
160 public: | |
6043 | 161 |
9880 | 162 // I'd love to rewrite this as a private method of the curl_handle |
163 // class, but you can't pass the va_list from the wrapper setopt to | |
164 // the curl_easy_setopt function. | |
165 #define setopt(option, parameter) \ | |
166 { \ | |
167 CURLcode res = curl_easy_setopt (rep->handle (), option, parameter); \ | |
168 if (res != CURLE_OK) \ | |
169 error ("%s", curl_easy_strerror (res)); \ | |
170 } | |
171 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
172 curl_handle (void) : rep (new curl_handle_rep ()) |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
173 { |
9880 | 174 rep->valid = false; |
175 } | |
176 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
177 curl_handle (const std::string& _host, const std::string& user, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
178 const std::string& passwd) : |
9880 | 179 rep (new curl_handle_rep ()) |
180 { | |
181 rep->host = _host; | |
182 init (user, passwd, std::cin, octave_stdout); | |
183 | |
184 std::string url = "ftp://" + _host; | |
185 setopt (CURLOPT_URL, url.c_str()); | |
6043 | 186 |
9880 | 187 // Setup the link, with no transfer |
188 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
189 perform (); |
9880 | 190 } |
191 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
192 curl_handle (const std::string& url, const std::string& method, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
193 const Cell& param, std::ostream& os, bool& retval) : |
9880 | 194 rep (new curl_handle_rep ()) |
195 { | |
196 retval = false; | |
197 | |
198 init ("", "", std::cin, os); | |
199 | |
200 setopt (CURLOPT_NOBODY, 0); | |
201 | |
202 // Don't need to store the parameters here as we can't change | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
203 // the URL after the handle is created |
9880 | 204 std::string query_string = form_query_string (param); |
6043 | 205 |
9880 | 206 if (method == "get") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
207 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
208 query_string = url + "?" + query_string; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
209 setopt (CURLOPT_URL, query_string.c_str ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
210 } |
9880 | 211 else if (method == "post") |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
212 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
213 setopt (CURLOPT_URL, url.c_str ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
214 setopt (CURLOPT_POSTFIELDS, query_string.c_str ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
215 } |
9880 | 216 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
217 setopt (CURLOPT_URL, url.c_str()); |
9880 | 218 |
219 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
220 retval = perform (false); |
9880 | 221 } |
222 | |
223 curl_handle (const curl_handle& h) : rep (h.rep) | |
6043 | 224 { |
9880 | 225 rep->count++; |
226 } | |
227 | |
228 ~curl_handle (void) | |
229 { | |
230 if (--rep->count == 0) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
231 delete rep; |
9880 | 232 } |
233 | |
234 curl_handle& operator = (const curl_handle& h) | |
235 { | |
236 if (this != &h) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
237 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
238 if (--rep->count == 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
239 delete rep; |
9880 | 240 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
241 rep = h.rep; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
242 rep->count++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
243 } |
9880 | 244 return *this; |
245 } | |
246 | |
247 bool is_valid (void) const | |
248 { | |
249 return rep->is_valid (); | |
6043 | 250 } |
9880 | 251 |
252 std::string lasterror (void) const | |
253 { | |
12963
27e5f0e79f19
Return better error codes from curl, even if connection is successful
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12782
diff
changeset
|
254 return std::string (curl_easy_strerror (rep->errnum)); |
9880 | 255 } |
256 | |
257 void set_ostream (std::ostream& os) const | |
258 { | |
259 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&os)); | |
260 } | |
261 | |
262 void set_istream (std::istream& is) const | |
6043 | 263 { |
9880 | 264 setopt (CURLOPT_READDATA, static_cast<void*> (&is)); |
265 } | |
266 | |
267 void ascii (void) const | |
268 { | |
269 setopt (CURLOPT_TRANSFERTEXT, 1); | |
270 rep->ascii = true; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
271 } |
9880 | 272 |
273 void binary (void) const | |
274 { | |
275 setopt (CURLOPT_TRANSFERTEXT, 0); | |
276 rep->ascii = false; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
277 } |
9880 | 278 |
279 bool is_ascii (void) const | |
280 { | |
281 return rep->is_ascii (); | |
282 } | |
283 | |
284 bool is_binary (void) const | |
285 { | |
286 return rep->is_binary (); | |
6043 | 287 } |
9880 | 288 |
289 void cwd (const std::string& path) const | |
290 { | |
291 struct curl_slist *slist = 0; | |
292 std::string cmd = "cwd " + path; | |
293 slist = curl_slist_append (slist, cmd.c_str()); | |
294 setopt (CURLOPT_POSTQUOTE, slist); | |
295 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
296 perform (); |
9880 | 297 setopt (CURLOPT_POSTQUOTE, 0); |
298 curl_slist_free_all (slist); | |
299 } | |
6043 | 300 |
9880 | 301 void del (const std::string& file) const |
302 { | |
303 struct curl_slist *slist = 0; | |
304 std::string cmd = "dele " + file; | |
305 slist = curl_slist_append (slist, cmd.c_str()); | |
306 setopt (CURLOPT_POSTQUOTE, slist); | |
307 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
308 perform (); |
9880 | 309 setopt (CURLOPT_POSTQUOTE, 0); |
310 curl_slist_free_all (slist); | |
311 } | |
312 | |
313 void rmdir (const std::string& path) const | |
314 { | |
315 struct curl_slist *slist = 0; | |
316 std::string cmd = "rmd " + path; | |
317 slist = curl_slist_append (slist, cmd.c_str()); | |
318 setopt (CURLOPT_POSTQUOTE, slist); | |
319 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
320 perform (); |
9880 | 321 setopt (CURLOPT_POSTQUOTE, 0); |
322 curl_slist_free_all (slist); | |
323 } | |
6043 | 324 |
9880 | 325 bool mkdir (const std::string& path, bool curlerror = true) const |
326 { | |
327 bool retval = false; | |
328 struct curl_slist *slist = 0; | |
329 std::string cmd = "mkd " + path; | |
330 slist = curl_slist_append (slist, cmd.c_str()); | |
331 setopt (CURLOPT_POSTQUOTE, slist); | |
332 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
333 retval = perform (curlerror); |
9880 | 334 setopt (CURLOPT_POSTQUOTE, 0); |
335 curl_slist_free_all (slist); | |
336 return retval; | |
337 } | |
6043 | 338 |
9880 | 339 void rename (const std::string& oldname, const std::string& newname) const |
340 { | |
341 struct curl_slist *slist = 0; | |
342 std::string cmd = "rnfr " + oldname; | |
343 slist = curl_slist_append (slist, cmd.c_str()); | |
344 cmd = "rnto " + newname; | |
345 slist = curl_slist_append (slist, cmd.c_str()); | |
346 setopt (CURLOPT_POSTQUOTE, slist); | |
347 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
348 perform (); |
9880 | 349 setopt (CURLOPT_POSTQUOTE, 0); |
350 curl_slist_free_all (slist); | |
351 } | |
352 | |
353 void put (const std::string& file, std::istream& is) const | |
354 { | |
355 std::string url = "ftp://" + rep->host + "/" + file; | |
356 setopt (CURLOPT_URL, url.c_str()); | |
357 setopt (CURLOPT_UPLOAD, 1); | |
358 setopt (CURLOPT_NOBODY, 0); | |
359 set_istream (is); | |
360 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
361 perform (); |
9880 | 362 set_istream (std::cin); |
363 setopt (CURLOPT_NOBODY, 1); | |
364 setopt (CURLOPT_UPLOAD, 0); | |
365 url = "ftp://" + rep->host; | |
366 setopt (CURLOPT_URL, url.c_str()); | |
367 } | |
7013 | 368 |
9880 | 369 void get (const std::string& file, std::ostream& os) const |
370 { | |
371 std::string url = "ftp://" + rep->host + "/" + file; | |
372 setopt (CURLOPT_URL, url.c_str()); | |
373 setopt (CURLOPT_NOBODY, 0); | |
374 set_ostream (os); | |
375 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
376 perform (); |
9880 | 377 set_ostream (octave_stdout); |
378 setopt (CURLOPT_NOBODY, 1); | |
379 url = "ftp://" + rep->host; | |
380 setopt (CURLOPT_URL, url.c_str()); | |
381 } | |
382 | |
383 void dir (void) const | |
384 { | |
385 std::string url = "ftp://" + rep->host + "/"; | |
386 setopt (CURLOPT_URL, url.c_str()); | |
387 setopt (CURLOPT_NOBODY, 0); | |
388 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
389 perform (); |
9880 | 390 setopt (CURLOPT_NOBODY, 1); |
391 url = "ftp://" + rep->host; | |
392 setopt (CURLOPT_URL, url.c_str()); | |
393 } | |
6390 | 394 |
9880 | 395 string_vector list (void) const |
396 { | |
397 std::ostringstream buf; | |
398 std::string url = "ftp://" + rep->host + "/"; | |
399 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&buf)); | |
400 setopt (CURLOPT_URL, url.c_str()); | |
401 setopt (CURLOPT_DIRLISTONLY, 1); | |
402 setopt (CURLOPT_NOBODY, 0); | |
403 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
404 perform (); |
9880 | 405 setopt (CURLOPT_NOBODY, 1); |
406 url = "ftp://" + rep->host; | |
407 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&octave_stdout)); | |
408 setopt (CURLOPT_DIRLISTONLY, 0); | |
409 setopt (CURLOPT_URL, url.c_str()); | |
410 | |
411 // Count number of directory entries | |
412 std::string str = buf.str (); | |
413 octave_idx_type n = 0; | |
414 size_t pos = 0; | |
415 while (true) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
416 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
417 pos = str.find_first_of('\n', pos); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
418 if (pos == std::string::npos) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
419 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
420 pos++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
421 n++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
422 } |
9880 | 423 string_vector retval (n); |
424 pos = 0; | |
425 for (octave_idx_type i = 0; i < n; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
426 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
427 size_t newpos = str.find_first_of('\n', pos); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
428 if (newpos == std::string::npos) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
429 break; |
9880 | 430 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
431 retval(i) = str.substr(pos, newpos - pos); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
432 pos = newpos + 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
433 } |
9880 | 434 return retval; |
435 } | |
436 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
437 void get_fileinfo (const std::string& filename, double& filesize, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
438 time_t& filetime, bool& fileisdir) const |
9880 | 439 { |
440 std::string path = pwd(); | |
6043 | 441 |
9880 | 442 std::string url = "ftp://" + rep->host + "/" + path + "/" + filename; |
443 setopt (CURLOPT_URL, url.c_str()); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
444 setopt (CURLOPT_FILETIME, 1); |
9880 | 445 setopt (CURLOPT_HEADERFUNCTION, throw_away); |
446 setopt (CURLOPT_WRITEFUNCTION, throw_away); | |
6043 | 447 |
9880 | 448 // FIXME |
449 // The MDTM command fails for a directory on the servers I tested | |
450 // so this is a means of testing for directories. It also means | |
451 // I can't get the date of directories! | |
452 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
453 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
454 if (! perform (false)) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
455 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
456 fileisdir = true; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
457 filetime = -1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
458 filesize = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
459 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
460 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
461 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
462 fileisdir = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
463 time_t ft; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
464 curl_easy_getinfo(rep->handle (), CURLINFO_FILETIME, &ft); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
465 filetime = ft; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
466 double fs; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
467 curl_easy_getinfo(rep->handle (), |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
468 CURLINFO_CONTENT_LENGTH_DOWNLOAD, &fs); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
469 filesize = fs; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
470 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
471 } |
6992 | 472 |
9880 | 473 setopt (CURLOPT_WRITEFUNCTION, write_data); |
474 setopt (CURLOPT_HEADERFUNCTION, 0); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
475 setopt (CURLOPT_FILETIME, 0); |
9880 | 476 url = "ftp://" + rep->host; |
477 setopt (CURLOPT_URL, url.c_str()); | |
478 | |
479 // The MDTM command seems to reset the path to the root with the | |
480 // servers I tested with, so cd again into the correct path. Make | |
481 // the path absolute so that this will work even with servers that | |
482 // don't end up in the root after an MDTM command. | |
483 cwd ("/" + path); | |
484 } | |
485 | |
486 std::string pwd (void) const | |
487 { | |
488 struct curl_slist *slist = 0; | |
489 std::string retval; | |
490 std::ostringstream buf; | |
6992 | 491 |
9880 | 492 slist = curl_slist_append (slist, "pwd"); |
493 setopt (CURLOPT_POSTQUOTE, slist); | |
494 setopt (CURLOPT_HEADERFUNCTION, write_data); | |
495 setopt (CURLOPT_WRITEHEADER, static_cast<void *>(&buf)); | |
496 | |
497 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
498 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
499 perform (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
500 retval = buf.str(); |
9880 | 501 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
502 // Can I assume that the path is alway in "" on the last line |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
503 size_t pos2 = retval.rfind ('"'); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
504 size_t pos1 = retval.rfind ('"', pos2 - 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
505 retval = retval.substr(pos1 + 1, pos2 - pos1 - 1); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
506 } |
9880 | 507 setopt (CURLOPT_HEADERFUNCTION, 0); |
508 setopt (CURLOPT_WRITEHEADER, 0); | |
509 setopt (CURLOPT_POSTQUOTE, 0); | |
510 curl_slist_free_all (slist); | |
511 | |
512 return retval; | |
513 } | |
6992 | 514 |
9880 | 515 bool perform (bool curlerror = true) const |
516 { | |
517 return rep->perform (curlerror); | |
518 } | |
519 | |
520 private: | |
521 curl_handle_rep *rep; | |
522 | |
523 std::string form_query_string (const Cell& param) | |
524 { | |
525 std::ostringstream query; | |
526 | |
527 for (int i = 0; i < param.numel (); i += 2) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
528 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
529 std::string name = param(i).string_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
530 std::string text = param(i+1).string_value (); |
9880 | 531 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
532 // Encode strings. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
533 char *enc_name = curl_easy_escape (rep->handle(), name.c_str (), |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
534 name.length ()); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
535 char *enc_text = curl_easy_escape (rep->handle(), text.c_str (), |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
536 text.length ()); |
9880 | 537 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
538 query << enc_name << "=" << enc_text; |
9880 | 539 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
540 curl_free (enc_name); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
541 curl_free (enc_text); |
9880 | 542 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
543 if (i < param.numel()-1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
544 query << "&"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
545 } |
9880 | 546 |
547 query.flush (); | |
6043 | 548 |
9880 | 549 return query.str (); |
550 } | |
551 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
552 void init (const std::string& user, const std::string& passwd, |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
553 std::istream& is, std::ostream& os) |
9880 | 554 { |
555 // No data transfer by default | |
556 setopt (CURLOPT_NOBODY, 1); | |
557 | |
558 // Set the username and password | |
9918
57b41617c9fd
avoid LIBCURL version check
John W. Eaton <jwe@octave.org>
parents:
9905
diff
changeset
|
559 std::string userpwd = user; |
57b41617c9fd
avoid LIBCURL version check
John W. Eaton <jwe@octave.org>
parents:
9905
diff
changeset
|
560 if (! passwd.empty ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
561 userpwd += ":" + passwd; |
10377
fb62fbbe28c0
urlwrite: don't set CURLOPT_USERPWD if userpwd is empty
David Bateman <dbateman@free.fr>
parents:
10250
diff
changeset
|
562 if (! userpwd.empty ()) |
fb62fbbe28c0
urlwrite: don't set CURLOPT_USERPWD if userpwd is empty
David Bateman <dbateman@free.fr>
parents:
10250
diff
changeset
|
563 setopt (CURLOPT_USERPWD, userpwd.c_str ()); |
9880 | 564 |
565 // Define our callback to get called when there's data to be written. | |
566 setopt (CURLOPT_WRITEFUNCTION, write_data); | |
6992 | 567 |
9880 | 568 // Set a pointer to our struct to pass to the callback. |
569 setopt (CURLOPT_WRITEDATA, static_cast<void*> (&os)); | |
570 | |
571 // Define our callback to get called when there's data to be read | |
572 setopt (CURLOPT_READFUNCTION, read_data); | |
573 | |
574 // Set a pointer to our struct to pass to the callback. | |
575 setopt (CURLOPT_READDATA, static_cast<void*> (&is)); | |
576 | |
577 // Follow redirects. | |
578 setopt (CURLOPT_FOLLOWLOCATION, true); | |
579 | |
580 // Don't use EPSV since connecting to sites that don't support it | |
581 // will hang for some time (3 minutes?) before moving on to try PASV | |
582 // instead. | |
583 setopt (CURLOPT_FTP_USE_EPSV, false); | |
584 | |
585 setopt (CURLOPT_NOPROGRESS, true); | |
586 setopt (CURLOPT_FAILONERROR, true); | |
6992 | 587 |
9880 | 588 setopt (CURLOPT_POSTQUOTE, 0); |
589 setopt (CURLOPT_QUOTE, 0); | |
590 } | |
591 | |
592 #undef setopt | |
593 }; | |
594 | |
595 class | |
596 curl_handles | |
597 { | |
598 public: | |
599 | |
600 typedef std::map<std::string, curl_handle>::iterator iterator; | |
601 typedef std::map<std::string, curl_handle>::const_iterator const_iterator; | |
6043 | 602 |
9880 | 603 curl_handles (void) : map () |
604 { | |
605 curl_global_init(CURL_GLOBAL_DEFAULT); | |
606 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
607 |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
608 ~curl_handles (void) |
9880 | 609 { |
610 // Remove the elements of the map explicitly as they should | |
611 // be deleted before the call to curl_global_cleanup | |
11548
50a7935f2512
Don't invalidate iterators when calling std::map::erase, found by cppcheck
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
11523
diff
changeset
|
612 map.erase (begin(), end()); |
6992 | 613 |
9880 | 614 curl_global_cleanup (); |
615 } | |
616 | |
617 iterator begin (void) { return iterator (map.begin ()); } | |
618 const_iterator begin (void) const { return const_iterator (map.begin ()); } | |
619 | |
620 iterator end (void) { return iterator (map.end ()); } | |
621 const_iterator end (void) const { return const_iterator (map.end ()); } | |
6992 | 622 |
9880 | 623 iterator seek (const std::string& k) { return map.find (k); } |
624 const_iterator seek (const std::string& k) const { return map.find (k); } | |
625 | |
626 std::string key (const_iterator p) const { return p->first; } | |
627 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
628 curl_handle& contents (const std::string& k) |
9880 | 629 { |
630 return map[k]; | |
631 } | |
632 | |
633 curl_handle contents (const std::string& k) const | |
634 { | |
635 const_iterator p = seek (k); | |
636 return p != end () ? p->second : curl_handle (); | |
637 } | |
638 | |
639 curl_handle& contents (iterator p) | |
640 { return p->second; } | |
6992 | 641 |
9880 | 642 curl_handle contents (const_iterator p) const |
643 { return p->second; } | |
644 | |
645 void del (const std::string& k) | |
646 { | |
647 iterator p = map.find (k); | |
648 | |
649 if (p != map.end ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
650 map.erase (p); |
9880 | 651 } |
6043 | 652 |
9880 | 653 private: |
654 std::map<std::string, curl_handle> map; | |
655 }; | |
656 | |
657 static curl_handles handles; | |
658 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
659 static void |
9880 | 660 cleanup_urlwrite (std::string filename) |
661 { | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
662 octave_unlink (filename); |
6043 | 663 } |
664 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
665 static void |
9880 | 666 reset_path (const curl_handle curl) |
667 { | |
668 curl.cwd (".."); | |
669 } | |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
670 |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
671 static void |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
672 delete_file (std::string file) |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
673 { |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
674 octave_unlink (file); |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
675 } |
9880 | 676 #endif |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
677 |
6043 | 678 DEFUN_DLD (urlwrite, args, nargout, |
679 "-*- texinfo -*-\n\ | |
10840 | 680 @deftypefn {Loadable Function} {} urlwrite (@var{url}, @var{localfile})\n\ |
6043 | 681 @deftypefnx {Loadable Function} {@var{f} =} urlwrite (@var{url}, @var{localfile})\n\ |
682 @deftypefnx {Loadable Function} {[@var{f}, @var{success}] =} urlwrite (@var{url}, @var{localfile})\n\ | |
683 @deftypefnx {Loadable Function} {[@var{f}, @var{success}, @var{message}] =} urlwrite (@var{url}, @var{localfile})\n\ | |
9880 | 684 Download a remote file specified by its @var{url} and save it as\n\ |
10840 | 685 @var{localfile}. For example:\n\ |
6043 | 686 \n\ |
687 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
688 @group\n\ |
12642
f96b9b9f141b
doc: Periodic grammarcheck and spellcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
689 urlwrite (\"ftp://ftp.octave.org/pub/octave/README\",\n\ |
7031 | 690 \"README.txt\");\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
691 @end group\n\ |
6043 | 692 @end example\n\ |
693 \n\ | |
694 The full path of the downloaded file is returned in @var{f}. The\n\ | |
695 variable @var{success} is 1 if the download was successful,\n\ | |
696 otherwise it is 0 in which case @var{message} contains an error\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
697 message. If no output argument is specified and an error occurs,\n\ |
6588 | 698 then the error is signaled through Octave's error handling mechanism.\n\ |
6043 | 699 \n\ |
700 This function uses libcurl. Curl supports, among others, the HTTP,\n\ | |
701 FTP and FILE protocols. Username and password may be specified in\n\ | |
702 the URL, for example:\n\ | |
703 \n\ | |
704 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
705 @group\n\ |
6588 | 706 urlwrite (\"http://username:password@@example.com/file.txt\",\n\ |
707 \"file.txt\");\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
708 @end group\n\ |
6043 | 709 @end example\n\ |
710 \n\ | |
711 GET and POST requests can be specified by @var{method} and @var{param}.\n\ | |
6589 | 712 The parameter @var{method} is either @samp{get} or @samp{post}\n\ |
6588 | 713 and @var{param} is a cell array of parameter and value pairs.\n\ |
714 For example:\n\ | |
6043 | 715 \n\ |
716 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
717 @group\n\ |
6588 | 718 urlwrite (\"http://www.google.com/search\", \"search.html\",\n\ |
719 \"get\", @{\"query\", \"octave\"@});\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
720 @end group\n\ |
6043 | 721 @end example\n\ |
722 @seealso{urlread}\n\ | |
723 @end deftypefn") | |
724 { | |
725 octave_value_list retval; | |
726 | |
9905
84a7c11ff928
Correctly compile even when libcurl is not present according to configure
Rik <rdrider0-list@yahoo.com>
parents:
9885
diff
changeset
|
727 #ifdef HAVE_CURL |
6043 | 728 |
729 int nargin = args.length (); | |
730 | |
731 // verify arguments | |
732 if (nargin != 2 && nargin != 4) | |
733 { | |
734 print_usage (); | |
735 return retval; | |
736 } | |
737 | |
738 std::string url = args(0).string_value(); | |
739 | |
740 if (error_state) | |
741 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
742 error ("urlwrite: URL must be a character string"); |
6043 | 743 return retval; |
744 } | |
745 | |
746 // name to store the file if download is succesful | |
747 std::string filename = args(1).string_value(); | |
748 | |
749 if (error_state) | |
750 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
751 error ("urlwrite: LOCALFILE must be a character string"); |
6043 | 752 return retval; |
753 } | |
754 | |
755 std::string method; | |
756 Cell param; // empty cell array | |
757 | |
758 if (nargin == 4) | |
759 { | |
760 method = args(2).string_value(); | |
761 | |
762 if (error_state) | |
763 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
764 error ("urlwrite: METHOD must be \"get\" or \"post\""); |
6043 | 765 return retval; |
766 } | |
767 | |
768 if (method != "get" && method != "post") | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
769 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
770 error ("urlwrite: METHOD must be \"get\" or \"post\""); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
771 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
772 } |
6043 | 773 |
774 param = args(3).cell_value(); | |
775 | |
776 if (error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
777 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
778 error ("urlwrite: parameters (PARAM) for get and post requests must be given as a cell"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
779 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
780 } |
6043 | 781 |
782 | |
783 if (param.numel () % 2 == 1 ) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
784 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
785 error ("urlwrite: number of elements in PARAM must be even"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
786 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
787 } |
6043 | 788 } |
789 | |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
790 // The file should only be deleted if it doesn't initially exist, we |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
791 // create it, and the download fails. We use unwind_protect to do |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
792 // it so that the deletion happens no matter how we exit the function. |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
793 |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
794 file_stat fs (filename); |
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
795 |
6986 | 796 std::ofstream ofile (filename.c_str(), std::ios::out | std::ios::binary); |
6043 | 797 |
6986 | 798 if (! ofile.is_open ()) |
6043 | 799 { |
800 error ("urlwrite: unable to open file"); | |
801 return retval; | |
802 } | |
803 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
804 unwind_protect_safe frame; |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
805 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
806 frame.add_fcn (cleanup_urlwrite, filename); |
9880 | 807 |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
808 bool ok; |
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
809 curl_handle curl = curl_handle (url, method, param, ofile, ok); |
6043 | 810 |
6986 | 811 ofile.close (); |
6043 | 812 |
9880 | 813 if (!error_state) |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
814 frame.discard (); |
9880 | 815 else |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
816 frame.run (); |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
817 |
6043 | 818 if (nargout > 0) |
819 { | |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
820 if (ok) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
821 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
822 retval(2) = std::string (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
823 retval(1) = true; |
10250 | 824 retval(0) = octave_env::make_absolute (filename); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
825 } |
8151
3725f819b5b3
urlwrite.cc (Furlwrite): delete files we create if download fails
John W. Eaton <jwe@octave.org>
parents:
7481
diff
changeset
|
826 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
827 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
828 retval(2) = curl.lasterror (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
829 retval(1) = false; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
830 retval(0) = std::string (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
831 } |
6043 | 832 } |
833 | |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
834 if (nargout < 2 && ! ok) |
9880 | 835 error ("urlwrite: curl: %s", curl.lasterror ().c_str ()); |
6043 | 836 |
837 #else | |
6981 | 838 error ("urlwrite: not available in this version of Octave"); |
6043 | 839 #endif |
840 | |
841 return retval; | |
842 } | |
843 | |
844 DEFUN_DLD (urlread, args, nargout, | |
845 "-*- texinfo -*-\n\ | |
10840 | 846 @deftypefn {Loadable Function} {@var{s} =} urlread (@var{url})\n\ |
6043 | 847 @deftypefnx {Loadable Function} {[@var{s}, @var{success}] =} urlread (@var{url})\n\ |
6549 | 848 @deftypefnx {Loadable Function} {[@var{s}, @var{success}, @var{message}] =} urlread (@var{url})\n\ |
6547 | 849 @deftypefnx {Loadable Function} {[@dots{}] =} urlread (@var{url}, @var{method}, @var{param})\n\ |
9880 | 850 Download a remote file specified by its @var{url} and return its content\n\ |
10840 | 851 in string @var{s}. For example:\n\ |
6043 | 852 \n\ |
853 @example\n\ | |
6588 | 854 s = urlread (\"ftp://ftp.octave.org/pub/octave/README\");\n\ |
6043 | 855 @end example\n\ |
856 \n\ | |
857 The variable @var{success} is 1 if the download was successful,\n\ | |
858 otherwise it is 0 in which case @var{message} contains an error\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
859 message. If no output argument is specified and an error occurs,\n\ |
6588 | 860 then the error is signaled through Octave's error handling mechanism.\n\ |
6043 | 861 \n\ |
862 This function uses libcurl. Curl supports, among others, the HTTP,\n\ | |
863 FTP and FILE protocols. Username and password may be specified in the\n\ | |
10840 | 864 URL@. For example:\n\ |
6043 | 865 \n\ |
866 @example\n\ | |
7031 | 867 s = urlread (\"http://user:password@@example.com/file.txt\");\n\ |
6043 | 868 @end example\n\ |
869 \n\ | |
870 GET and POST requests can be specified by @var{method} and @var{param}.\n\ | |
6588 | 871 The parameter @var{method} is either @samp{get} or @samp{post}\n\ |
872 and @var{param} is a cell array of parameter and value pairs.\n\ | |
10840 | 873 For example:\n\ |
6043 | 874 \n\ |
875 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
876 @group\n\ |
6588 | 877 s = urlread (\"http://www.google.com/search\", \"get\",\n\ |
878 @{\"query\", \"octave\"@});\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
879 @end group\n\ |
6043 | 880 @end example\n\ |
881 @seealso{urlwrite}\n\ | |
882 @end deftypefn") | |
883 { | |
6588 | 884 // Octave's return value |
6043 | 885 octave_value_list retval; |
886 | |
9905
84a7c11ff928
Correctly compile even when libcurl is not present according to configure
Rik <rdrider0-list@yahoo.com>
parents:
9885
diff
changeset
|
887 #ifdef HAVE_CURL |
6043 | 888 |
889 int nargin = args.length (); | |
890 | |
891 // verify arguments | |
892 if (nargin != 1 && nargin != 3) | |
893 { | |
894 print_usage (); | |
895 return retval; | |
896 } | |
897 | |
898 std::string url = args(0).string_value(); | |
899 | |
900 if (error_state) | |
901 { | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
902 error ("urlread: URL must be a character string"); |
6043 | 903 return retval; |
904 } | |
905 | |
906 std::string method; | |
907 Cell param; // empty cell array | |
908 | |
909 if (nargin == 3) | |
910 { | |
911 method = args(1).string_value(); | |
912 | |
913 if (error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
914 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
915 error ("urlread: METHOD must be \"get\" or \"post\""); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
916 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
917 } |
6043 | 918 |
919 if (method != "get" && method != "post") | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
920 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
921 error ("urlread: METHOD must be \"get\" or \"post\""); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
922 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
923 } |
6043 | 924 |
925 param = args(2).cell_value(); | |
926 | |
927 if (error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
928 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
929 error ("urlread: parameters (PARAM) for get and post requests must be given as a cell"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
930 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
931 } |
6043 | 932 |
933 if (param.numel () % 2 == 1 ) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
934 { |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
935 error ("urlread: number of elements in PARAM must be even"); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
936 return retval; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
937 } |
6043 | 938 } |
939 | |
6986 | 940 std::ostringstream buf; |
6043 | 941 |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
942 bool ok; |
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
943 curl_handle curl = curl_handle (url, method, param, buf, ok); |
6043 | 944 |
945 if (nargout > 0) | |
946 { | |
6986 | 947 retval(0) = buf.str (); |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
948 retval(1) = ok; |
6986 | 949 // Return empty string if no error occured. |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
950 retval(2) = ok ? "" : curl.lasterror (); |
6043 | 951 } |
952 | |
13978
a33ec41d0340
Fix error reporting in urlwrite (bug #34971)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12963
diff
changeset
|
953 if (nargout < 2 && ! ok) |
9880 | 954 error ("urlread: curl: %s", curl.lasterror().c_str()); |
6043 | 955 |
956 #else | |
6981 | 957 error ("urlread: not available in this version of Octave"); |
6043 | 958 #endif |
959 | |
960 return retval; | |
961 } | |
9880 | 962 |
963 DEFUN_DLD (__ftp__, args, , | |
964 "-*- texinfo -*-\n\ | |
10840 | 965 @deftypefn {Loadable Function} {} __ftp__ (@var{handle}, @var{host})\n\ |
9880 | 966 @deftypefnx {Loadable Function} {} __ftp__ (@var{handle}, @var{host}, @var{username}, @var{password})\n\ |
967 Undocumented internal function\n\ | |
968 @end deftypefn") | |
969 { | |
970 #ifdef HAVE_CURL | |
971 int nargin = args.length (); | |
972 std::string handle; | |
973 std::string host; | |
974 std::string user = "anonymous"; | |
975 std::string passwd = ""; | |
976 | |
977 if (nargin < 2 || nargin > 4) | |
978 error ("incorrect number of arguments"); | |
979 else | |
980 { | |
981 handle = args(0).string_value (); | |
982 host = args(1).string_value (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
983 |
9880 | 984 if (nargin > 1) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
985 user = args(2).string_value (); |
9880 | 986 |
987 if (nargin > 2) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
988 passwd = args(3).string_value (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
989 |
9880 | 990 if (!error_state) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
991 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
992 handles.contents (handle) = curl_handle (host, user, passwd); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
993 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
994 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
995 handles.del (handle); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
996 } |
9880 | 997 } |
998 #else | |
999 error ("__ftp__: not available in this version of Octave"); | |
1000 #endif | |
1001 | |
1002 return octave_value (); | |
1003 } | |
1004 | |
1005 DEFUN_DLD (__ftp_pwd__, args, , | |
1006 "-*- texinfo -*-\n\ | |
1007 @deftypefn {Loadable Function} {} __ftp_pwd__ (@var{handle})\n\ | |
1008 Undocumented internal function\n\ | |
1009 @end deftypefn") | |
1010 { | |
1011 octave_value retval; | |
1012 #ifdef HAVE_CURL | |
1013 int nargin = args.length (); | |
1014 | |
1015 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1016 error ("__ftp_pwd__: incorrect number of arguments"); |
9880 | 1017 else |
1018 { | |
1019 std::string handle = args(0).string_value (); | |
1020 | |
1021 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1022 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1023 const curl_handle curl = handles.contents (handle); |
9880 | 1024 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1025 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1026 retval = curl.pwd (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1027 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1028 error ("__ftp_pwd__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1029 } |
9880 | 1030 } |
1031 #else | |
1032 error ("__ftp_pwd__: not available in this version of Octave"); | |
1033 #endif | |
1034 | |
1035 return retval; | |
1036 } | |
1037 | |
1038 DEFUN_DLD (__ftp_cwd__, args, , | |
1039 "-*- texinfo -*-\n\ | |
1040 @deftypefn {Loadable Function} {} __ftp_cwd__ (@var{handle}, @var{path})\n\ | |
1041 Undocumented internal function\n\ | |
1042 @end deftypefn") | |
1043 { | |
1044 #ifdef HAVE_CURL | |
1045 int nargin = args.length (); | |
1046 | |
1047 if (nargin != 1 && nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1048 error ("__ftp_cwd__: incorrect number of arguments"); |
9880 | 1049 else |
1050 { | |
1051 std::string handle = args(0).string_value (); | |
1052 std::string path = ""; | |
1053 | |
1054 if (nargin > 1) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1055 path = args(1).string_value (); |
9880 | 1056 |
1057 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1058 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1059 const curl_handle curl = handles.contents (handle); |
9880 | 1060 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1061 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1062 curl.cwd (path); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1063 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1064 error ("__ftp_cwd__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1065 } |
9880 | 1066 } |
1067 #else | |
1068 error ("__ftp_cwd__: not available in this version of Octave"); | |
1069 #endif | |
1070 | |
1071 return octave_value (); | |
1072 } | |
1073 | |
1074 DEFUN_DLD (__ftp_dir__, args, nargout, | |
1075 "-*- texinfo -*-\n\ | |
1076 @deftypefn {Loadable Function} {} __ftp_dir__ (@var{handle})\n\ | |
1077 Undocumented internal function\n\ | |
1078 @end deftypefn") | |
1079 { | |
1080 octave_value retval; | |
1081 #ifdef HAVE_CURL | |
1082 int nargin = args.length (); | |
1083 | |
1084 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1085 error ("__ftp_dir__: incorrect number of arguments"); |
9880 | 1086 else |
1087 { | |
1088 std::string handle = args(0).string_value (); | |
1089 | |
1090 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1091 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1092 const curl_handle curl = handles.contents (handle); |
9880 | 1093 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1094 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1095 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1096 if (nargout == 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1097 curl.dir (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1098 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1099 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1100 string_vector sv = curl.list (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1101 octave_idx_type n = sv.length (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1102 if (n == 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1103 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1104 string_vector flds (5); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1105 flds(0) = "name"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1106 flds(1) = "date"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1107 flds(2) = "bytes"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1108 flds(3) = "isdir"; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1109 flds(4) = "datenum"; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1110 retval = octave_map (flds); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1111 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1112 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1113 { |
11050
b1ee705aef45
urlwrite.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10840
diff
changeset
|
1114 octave_map st; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1115 Cell filectime (dim_vector (n, 1)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1116 Cell filesize (dim_vector (n, 1)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1117 Cell fileisdir (dim_vector (n, 1)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1118 Cell filedatenum (dim_vector (n, 1)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1119 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1120 st.assign ("name", Cell (sv)); |
9880 | 1121 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1122 for (octave_idx_type i = 0; i < n; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1123 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1124 time_t ftime; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1125 bool fisdir; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1126 double fsize; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1127 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1128 curl.get_fileinfo (sv(i), fsize, ftime, fisdir); |
9880 | 1129 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1130 fileisdir (i) = fisdir; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1131 filectime (i) = ctime (&ftime); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1132 filesize (i) = fsize; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1133 filedatenum (i) = double (ftime); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1134 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1135 st.assign ("date", filectime); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1136 st.assign ("bytes", filesize); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1137 st.assign ("isdir", fileisdir); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1138 st.assign ("datenum", filedatenum); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1139 retval = st; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1140 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1141 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1142 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1143 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1144 error ("__ftp_dir__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1145 } |
9880 | 1146 } |
1147 #else | |
1148 error ("__ftp_dir__: not available in this version of Octave"); | |
1149 #endif | |
1150 | |
1151 return retval; | |
1152 } | |
1153 | |
1154 DEFUN_DLD (__ftp_ascii__, args, , | |
1155 "-*- texinfo -*-\n\ | |
1156 @deftypefn {Loadable Function} {} __ftp_ascii__ (@var{handle})\n\ | |
1157 Undocumented internal function\n\ | |
1158 @end deftypefn") | |
1159 { | |
1160 #ifdef HAVE_CURL | |
1161 int nargin = args.length (); | |
1162 | |
1163 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1164 error ("__ftp_ascii__: incorrect number of arguments"); |
9880 | 1165 else |
1166 { | |
1167 std::string handle = args(0).string_value (); | |
1168 | |
1169 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1170 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1171 const curl_handle curl = handles.contents (handle); |
9880 | 1172 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1173 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1174 curl.ascii (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1175 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1176 error ("__ftp_ascii__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1177 } |
9880 | 1178 } |
1179 #else | |
1180 error ("__ftp_ascii__: not available in this version of Octave"); | |
1181 #endif | |
1182 | |
1183 return octave_value (); | |
1184 } | |
1185 | |
1186 DEFUN_DLD (__ftp_binary__, args, , | |
1187 "-*- texinfo -*-\n\ | |
1188 @deftypefn {Loadable Function} {} __ftp_binary__ (@var{handle})\n\ | |
1189 Undocumented internal function\n\ | |
1190 @end deftypefn") | |
1191 { | |
1192 #ifdef HAVE_CURL | |
1193 int nargin = args.length (); | |
1194 | |
1195 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1196 error ("__ftp_binary__: incorrect number of arguments"); |
9880 | 1197 else |
1198 { | |
1199 std::string handle = args(0).string_value (); | |
1200 | |
1201 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1202 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1203 const curl_handle curl = handles.contents (handle); |
9880 | 1204 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1205 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1206 curl.binary (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1207 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1208 error ("__ftp_binary__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1209 } |
9880 | 1210 } |
1211 #else | |
1212 error ("__ftp_binary__: not available in this version of Octave"); | |
1213 #endif | |
1214 | |
1215 return octave_value (); | |
1216 } | |
1217 | |
1218 DEFUN_DLD (__ftp_close__, args, , | |
1219 "-*- texinfo -*-\n\ | |
1220 @deftypefn {Loadable Function} {} __ftp_close__ (@var{handle})\n\ | |
1221 Undocumented internal function\n\ | |
1222 @end deftypefn") | |
1223 { | |
1224 #ifdef HAVE_CURL | |
1225 int nargin = args.length (); | |
1226 | |
1227 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1228 error ("__ftp_close__: incorrect number of arguments"); |
9880 | 1229 else |
1230 { | |
1231 std::string handle = args(0).string_value (); | |
1232 | |
1233 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1234 handles.del (handle); |
9880 | 1235 } |
1236 #else | |
1237 error ("__ftp_close__: not available in this version of Octave"); | |
1238 #endif | |
1239 | |
1240 return octave_value (); | |
1241 } | |
1242 | |
1243 DEFUN_DLD (__ftp_mode__, args, , | |
1244 "-*- texinfo -*-\n\ | |
1245 @deftypefn {Loadable Function} {} __ftp_mode__ (@var{handle})\n\ | |
1246 Undocumented internal function\n\ | |
1247 @end deftypefn") | |
1248 { | |
1249 octave_value retval; | |
1250 #ifdef HAVE_CURL | |
1251 int nargin = args.length (); | |
1252 | |
1253 if (nargin != 1) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1254 error ("__ftp_mode__: incorrect number of arguments"); |
9880 | 1255 else |
1256 { | |
1257 std::string handle = args(0).string_value (); | |
1258 | |
1259 | |
1260 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1261 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1262 const curl_handle curl = handles.contents (handle); |
9880 | 1263 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1264 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1265 retval = (curl.is_ascii() ? "ascii" : "binary"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1266 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1267 error ("__ftp_binary__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1268 } |
9880 | 1269 } |
1270 #else | |
1271 error ("__ftp_mode__: not available in this version of Octave"); | |
1272 #endif | |
1273 | |
1274 return retval; | |
1275 } | |
1276 | |
1277 DEFUN_DLD (__ftp_delete__, args, , | |
1278 "-*- texinfo -*-\n\ | |
1279 @deftypefn {Loadable Function} {} __ftp_delete__ (@var{handle}, @var{path})\n\ | |
1280 Undocumented internal function\n\ | |
1281 @end deftypefn") | |
1282 { | |
1283 #ifdef HAVE_CURL | |
1284 int nargin = args.length (); | |
1285 | |
1286 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1287 error ("__ftp_delete__: incorrect number of arguments"); |
9880 | 1288 else |
1289 { | |
1290 std::string handle = args(0).string_value (); | |
1291 std::string file = args(1).string_value (); | |
1292 | |
1293 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1294 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1295 const curl_handle curl = handles.contents (handle); |
9880 | 1296 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1297 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1298 curl.del (file); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1299 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1300 error ("__ftp_delete__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1301 } |
9880 | 1302 } |
1303 #else | |
1304 error ("__ftp_delete__: not available in this version of Octave"); | |
1305 #endif | |
1306 | |
1307 return octave_value (); | |
1308 } | |
1309 | |
1310 DEFUN_DLD (__ftp_rmdir__, args, , | |
1311 "-*- texinfo -*-\n\ | |
1312 @deftypefn {Loadable Function} {} __ftp_rmdir__ (@var{handle}, @var{path})\n\ | |
1313 Undocumented internal function\n\ | |
1314 @end deftypefn") | |
1315 { | |
1316 #ifdef HAVE_CURL | |
1317 int nargin = args.length (); | |
1318 | |
1319 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1320 error ("__ftp_rmdir__: incorrect number of arguments"); |
9880 | 1321 else |
1322 { | |
1323 std::string handle = args(0).string_value (); | |
1324 std::string dir = args(1).string_value (); | |
1325 | |
1326 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1327 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1328 const curl_handle curl = handles.contents (handle); |
9880 | 1329 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1330 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1331 curl.rmdir (dir); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1332 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1333 error ("__ftp_rmdir__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1334 } |
9880 | 1335 } |
1336 #else | |
1337 error ("__ftp_rmdir__: not available in this version of Octave"); | |
1338 #endif | |
1339 | |
1340 return octave_value (); | |
1341 } | |
1342 | |
1343 DEFUN_DLD (__ftp_mkdir__, args, , | |
1344 "-*- texinfo -*-\n\ | |
1345 @deftypefn {Loadable Function} {} __ftp_mkdir__ (@var{handle}, @var{path})\n\ | |
1346 Undocumented internal function\n\ | |
1347 @end deftypefn") | |
1348 { | |
1349 #ifdef HAVE_CURL | |
1350 int nargin = args.length (); | |
1351 | |
1352 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1353 error ("__ftp_mkdir__: incorrect number of arguments"); |
9880 | 1354 else |
1355 { | |
1356 std::string handle = args(0).string_value (); | |
1357 std::string dir = args(1).string_value (); | |
1358 | |
1359 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1360 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1361 const curl_handle curl = handles.contents (handle); |
9880 | 1362 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1363 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1364 curl.mkdir (dir); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1365 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1366 error ("__ftp_mkdir__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1367 } |
9880 | 1368 } |
1369 #else | |
1370 error ("__ftp_mkdir__: not available in this version of Octave"); | |
1371 #endif | |
1372 | |
1373 return octave_value (); | |
1374 } | |
1375 | |
1376 DEFUN_DLD (__ftp_rename__, args, , | |
1377 "-*- texinfo -*-\n\ | |
1378 @deftypefn {Loadable Function} {} __ftp_rename__ (@var{handle}, @var{path})\n\ | |
1379 Undocumented internal function\n\ | |
1380 @end deftypefn") | |
1381 { | |
1382 #ifdef HAVE_CURL | |
1383 int nargin = args.length (); | |
1384 | |
1385 if (nargin != 3) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1386 error ("__ftp_rename__: incorrect number of arguments"); |
9880 | 1387 else |
1388 { | |
1389 std::string handle = args(0).string_value (); | |
1390 std::string oldname = args(1).string_value (); | |
1391 std::string newname = args(2).string_value (); | |
1392 | |
1393 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1394 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1395 const curl_handle curl = handles.contents (handle); |
9880 | 1396 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1397 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1398 curl.rename (oldname, newname); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1399 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1400 error ("__ftp_rename__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1401 } |
9880 | 1402 } |
1403 #else | |
1404 error ("__ftp_rename__: not available in this version of Octave"); | |
1405 #endif | |
1406 | |
1407 return octave_value (); | |
1408 } | |
1409 | |
9905
84a7c11ff928
Correctly compile even when libcurl is not present according to configure
Rik <rdrider0-list@yahoo.com>
parents:
9885
diff
changeset
|
1410 #ifdef HAVE_CURL |
9880 | 1411 static string_vector |
1412 mput_directory (const curl_handle& curl, const std::string& base, | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1413 const std::string& dir) |
9880 | 1414 { |
1415 string_vector retval; | |
1416 | |
1417 if (! curl.mkdir (dir, false)) | |
1418 warning ("__ftp_mput__: can not create the remote directory ""%s""", | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1419 (base.length() == 0 ? dir : base + |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1420 file_ops::dir_sep_str () + dir).c_str ()); |
9880 | 1421 |
1422 curl.cwd (dir); | |
1423 | |
1424 if (! error_state) | |
1425 { | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1426 unwind_protect_safe frame; |
9880 | 1427 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1428 frame.add_fcn (reset_path, curl); |
9880 | 1429 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1430 std::string realdir = base.length() == 0 ? dir : base + |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1431 file_ops::dir_sep_str () + dir; |
9880 | 1432 |
1433 dir_entry dirlist (realdir); | |
1434 | |
1435 if (dirlist) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1436 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1437 string_vector files = dirlist.read (); |
9880 | 1438 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1439 for (octave_idx_type i = 0; i < files.length (); i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1440 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1441 std::string file = files (i); |
9880 | 1442 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1443 if (file == "." || file == "..") |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1444 continue; |
9880 | 1445 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1446 std::string realfile = realdir + file_ops::dir_sep_str () + file; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1447 file_stat fs (realfile); |
9880 | 1448 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1449 if (! fs.exists ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1450 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1451 error ("__ftp__mput: file ""%s"" does not exist", |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1452 realfile.c_str ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1453 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1454 } |
9880 | 1455 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1456 if (fs.is_dir ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1457 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1458 retval.append (mput_directory (curl, realdir, file)); |
9880 | 1459 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1460 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1461 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1462 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1463 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1464 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1465 // FIXME Does ascii mode need to be flagged here? |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1466 std::ifstream ifile (realfile.c_str(), std::ios::in | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1467 std::ios::binary); |
9880 | 1468 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1469 if (! ifile.is_open ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1470 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1471 error ("__ftp_mput__: unable to open file ""%s""", |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1472 realfile.c_str ()); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1473 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1474 } |
9880 | 1475 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1476 curl.put (file, ifile); |
9880 | 1477 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1478 ifile.close (); |
9880 | 1479 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1480 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1481 break; |
9880 | 1482 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1483 retval.append (realfile); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1484 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1485 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1486 } |
9880 | 1487 else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1488 error ("__ftp_mput__: can not read the directory ""%s""", |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1489 realdir.c_str()); |
9880 | 1490 } |
1491 | |
1492 return retval; | |
1493 } | |
9905
84a7c11ff928
Correctly compile even when libcurl is not present according to configure
Rik <rdrider0-list@yahoo.com>
parents:
9885
diff
changeset
|
1494 #endif |
9880 | 1495 |
1496 DEFUN_DLD (__ftp_mput__, args, nargout, | |
1497 "-*- texinfo -*-\n\ | |
1498 @deftypefn {Loadable Function} {} __ftp_mput__ (@var{handle}, @var{files})\n\ | |
1499 Undocumented internal function\n\ | |
1500 @end deftypefn") | |
1501 { | |
1502 string_vector retval; | |
1503 | |
1504 #ifdef HAVE_CURL | |
1505 int nargin = args.length (); | |
1506 | |
1507 if (nargin != 2) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1508 error ("__ftp_mput__: incorrect number of arguments"); |
9880 | 1509 else |
1510 { | |
1511 std::string handle = args(0).string_value (); | |
1512 std::string pat = args(1).string_value (); | |
1513 | |
1514 if (!error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1515 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1516 const curl_handle curl = handles.contents (handle); |
9880 | 1517 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1518 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1519 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1520 glob_match pattern (file_ops::tilde_expand (pat)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1521 string_vector files = pattern.glob (); |
9880 | 1522 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1523 for (octave_idx_type i = 0; i < files.length (); i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1524 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1525 std::string file = files (i); |
9880 | 1526 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1527 file_stat fs (file); |
9880 | 1528 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1529 if (! fs.exists ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1530 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1531 error ("__ftp__mput: file does not exist"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1532 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1533 } |
9880 | 1534 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1535 if (fs.is_dir ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1536 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1537 retval.append (mput_directory (curl, "", file)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1538 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1539 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1540 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1541 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1542 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1543 // FIXME Does ascii mode need to be flagged here? |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1544 std::ifstream ifile (file.c_str(), std::ios::in | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1545 std::ios::binary); |
9880 | 1546 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1547 if (! ifile.is_open ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1548 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1549 error ("__ftp_mput__: unable to open file"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1550 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1551 } |
9880 | 1552 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1553 curl.put (file, ifile); |
9880 | 1554 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1555 ifile.close (); |
9880 | 1556 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1557 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1558 break; |
9880 | 1559 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1560 retval.append (file); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1561 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1562 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1563 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1564 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1565 error ("__ftp_mput__: invalid ftp handle"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1566 } |
9880 | 1567 } |
1568 #else | |
1569 error ("__ftp_mput__: not available in this version of Octave"); | |
1570 #endif | |
1571 | |
1572 return (nargout > 0 ? octave_value (retval) : octave_value ()); | |
1573 } | |
1574 | |
1575 #ifdef HAVE_CURL | |
1576 static void | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1577 getallfiles (const curl_handle& curl, const std::string& dir, |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1578 const std::string& target) |
9880 | 1579 { |
1580 std::string sep = file_ops::dir_sep_str (); | |
1581 file_stat fs (dir); | |
1582 | |
1583 if (!fs || !fs.is_dir ()) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1584 { |
9880 | 1585 std::string msg; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10154
diff
changeset
|
1586 int status = octave_mkdir (dir, 0777, msg); |
9880 | 1587 |
1588 if (status < 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1589 error ("__ftp_mget__: can't create directory %s%s%s. %s", |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1590 target.c_str(), sep.c_str(), dir.c_str(), msg.c_str()); |
9880 | 1591 } |
1592 | |
1593 if (! error_state) | |
1594 { | |
1595 curl.cwd (dir); | |
1596 | |
1597 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1598 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1599 unwind_protect_safe frame; |
9880 | 1600 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1601 frame.add_fcn (reset_path, curl); |
9880 | 1602 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1603 string_vector sv = curl.list (); |
9880 | 1604 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1605 for (octave_idx_type i = 0; i < sv.length (); i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1606 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1607 time_t ftime; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1608 bool fisdir; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1609 double fsize; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1610 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1611 curl.get_fileinfo (sv(i), fsize, ftime, fisdir); |
9880 | 1612 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1613 if (fisdir) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1614 getallfiles (curl, sv(i), target + dir + sep); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1615 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1616 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1617 std::string realfile = target + dir + sep + sv(i); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1618 std::ofstream ofile (realfile.c_str(), |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1619 std::ios::out | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1620 std::ios::binary); |
9880 | 1621 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1622 if (! ofile.is_open ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1623 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1624 error ("__ftp_mget__: unable to open file"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1625 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1626 } |
9880 | 1627 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1628 unwind_protect_safe frame2; |
9880 | 1629 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1630 frame2.add_fcn (delete_file, realfile); |
9880 | 1631 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1632 curl.get (sv(i), ofile); |
9880 | 1633 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1634 ofile.close (); |
9880 | 1635 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1636 if (!error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1637 frame2.discard (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1638 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1639 frame2.run (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1640 } |
9880 | 1641 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1642 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1643 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1644 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1645 } |
9880 | 1646 } |
1647 } | |
1648 #endif | |
1649 | |
1650 DEFUN_DLD (__ftp_mget__, args, , | |
1651 "-*- texinfo -*-\n\ | |
1652 @deftypefn {Loadable Function} {} __ftp_mget__ (@var{handle}, @var{files})\n\ | |
1653 Undocumented internal function\n\ | |
1654 @end deftypefn") | |
1655 { | |
1656 #ifdef HAVE_CURL | |
1657 int nargin = args.length (); | |
1658 | |
1659 if (nargin != 2 && nargin != 3) | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11548
diff
changeset
|
1660 error ("__ftp_mget__: incorrect number of arguments"); |
9880 | 1661 else |
1662 { | |
1663 std::string handle = args(0).string_value (); | |
1664 std::string file = args(1).string_value (); | |
1665 std::string target; | |
1666 | |
1667 if (nargin == 3) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1668 target = args(2).string_value () + file_ops::dir_sep_str (); |
9880 | 1669 |
1670 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1671 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1672 const curl_handle curl = handles.contents (handle); |
9880 | 1673 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1674 if (curl.is_valid ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1675 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1676 string_vector sv = curl.list (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1677 octave_idx_type n = 0; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1678 glob_match pattern (file); |
9880 | 1679 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1680 for (octave_idx_type i = 0; i < sv.length (); i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1681 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1682 if (pattern.match (sv(i))) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1683 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1684 n++; |
9880 | 1685 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1686 time_t ftime; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1687 bool fisdir; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1688 double fsize; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1689 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1690 curl.get_fileinfo (sv(i), fsize, ftime, fisdir); |
9880 | 1691 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1692 if (fisdir) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1693 getallfiles (curl, sv(i), target); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1694 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1695 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1696 std::ofstream ofile ((target + sv(i)).c_str(), |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
1697 std::ios::out | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1698 std::ios::binary); |
9880 | 1699 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1700 if (! ofile.is_open ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1701 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1702 error ("__ftp_mget__: unable to open file"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1703 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1704 } |
9880 | 1705 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9918
diff
changeset
|
1706 unwind_protect_safe frame; |
9880 | 1707 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1708 frame.add_fcn (delete_file, target + sv(i)); |
9880 | 1709 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1710 curl.get (sv(i), ofile); |
9880 | 1711 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1712 ofile.close (); |
9880 | 1713 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1714 if (!error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1715 frame.discard (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1716 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1717 frame.run (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1718 } |
9880 | 1719 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1720 if (error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1721 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1722 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1723 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1724 if (n == 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1725 error ("__ftp_mget__: file not found"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1726 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
10084
diff
changeset
|
1727 } |
9880 | 1728 } |
1729 #else | |
1730 error ("__ftp_mget__: not available in this version of Octave"); | |
1731 #endif | |
1732 | |
1733 return octave_value (); | |
1734 } |