annotate src/text/gftp-text.c @ 374:d207b8241e96

2003-1-21 Brian Masney <masneyb@gftp.org> * lib/config_file.c lib/gftp.h - set the character string arguments to const for the following functions: gftp_lookup_global_option(), gftp_lookup_request_option(), gftp_lookup_bookmark_option(), gftp_set_global_option(), gftp_set_request_option(), gftp_set_bookmark_option() * lib/misc.c lib/gftp.h - set the character string arguments to const for the function gftp_match_filespec() * src/gtk/gftp-gtk.c src/gtk/menu-items.c src/uicommon/gftpui.c - moved more UI independant parts to the uicommon directory. Moved some GUI specific functionality into gftp-gtk.c * src/text/gftp-text.c src/gtk/gftp-gtk.c src/uicommon/gftpui.c - pass the local/remote uidata/request structures to process_command(). Removed old function gftpui_common_init(). Added new gftpui_common_init() that sets up common functionality for a port. * src/gtk/gtkui.c src/gtk/gtkui_transfer.c - moved gftpui_add_file_to_transfer() to gtkui_transfer.c * src/gtk/gtkui_transfer.c - cleaned up these functions some and made them more modular * src/uicommon/gftpui.c src/uicommon/gftpui.h - for all of the command line functions, make the command argument a constant
author masneyb
date Wed, 21 Jan 2004 23:35:40 +0000
parents 7cb3327f96f7
children 14da115b149b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
2 /* gftp-text.c - text port of gftp */
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
4 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
9 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
14 /* */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
18 /*****************************************************************************/
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
19
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
20 #include "gftp-text.h"
33
c8ec7877432e 2002-10-06 Brian Masney <masneyb@gftp.org>
masneyb
parents: 16
diff changeset
21 static const char cvsid[] = "$Id$";
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
22
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
23 static gftp_request * gftp_text_locreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
24 static gftp_request * gftp_text_remreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
25
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
26 int
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
27 gftp_text_get_win_size (void)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
28 {
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
29 struct winsize size;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
30 int ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
31
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
32 if (ioctl (0, TIOCGWINSZ, (char *) &size) < 0)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
33 ret = 80;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
34 else
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
35 ret = size.ws_col;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
36
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
37 return (ret);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
38 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
39
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
40
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
41 void
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
42 gftp_text_log (gftp_logging_level level, gftp_request * request,
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
43 const char *string, ...)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
44 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
45 char tempstr[512], *stpos, *endpos, *utf8_str = NULL, *outstr;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
46 va_list argp;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
47 int sw;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
48
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
49 g_return_if_fail (string != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
50
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
51 switch (level)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
52 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
53 case gftp_logging_send:
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
54 printf ("%s", GFTPUI_COMMON_COLOR_GREEN);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
55 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
56 case gftp_logging_recv:
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
57 printf ("%s", GFTPUI_COMMON_COLOR_YELLOW);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
58 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
59 case gftp_logging_error:
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
60 printf ("%s", GFTPUI_COMMON_COLOR_RED);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
61 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
62 default:
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
63 printf ("%s", GFTPUI_COMMON_COLOR_DEFAULT);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
64 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
65 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
66
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
67 va_start (argp, string);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
68 g_vsnprintf (tempstr, sizeof (tempstr), string, argp);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
69 va_end (argp);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
70
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
71 #if GLIB_MAJOR_VERSION > 1
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
72 if (!g_utf8_validate (tempstr, -1, NULL))
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
73 utf8_str = gftp_string_to_utf8 (request, tempstr);
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
74 #endif
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
75
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
76 if (utf8_str != NULL)
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
77 outstr = utf8_str;
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
78 else
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
79 outstr = tempstr;
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
80
354
2ea37b3c0158 2003-1-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 341
diff changeset
81 if (gftp_logfd != NULL && level != gftp_logging_misc_nolog)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
82 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
83 fwrite (outstr, 1, strlen (outstr), gftp_logfd);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
84 if (ferror (gftp_logfd))
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
85 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
86 fclose (gftp_logfd);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
87 gftp_logfd = NULL;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
88 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
89 else
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
90 fflush (gftp_logfd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
91 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
92
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
93 sw = gftp_text_get_win_size ();
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
94 stpos = outstr;
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
95 endpos = outstr + 1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
96 do
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
97 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
98 if (strlen (stpos) <= sw)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
99 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
100 printf ("%s", stpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
101 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
102 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
103 for (endpos = stpos + sw - 1; *endpos != ' ' && endpos > stpos; endpos--);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
104 if (endpos != stpos)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
105 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
106 *endpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
107 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
108 printf ("%s\n", stpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
109 stpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
110 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
111 while (stpos != endpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
112
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
113 printf ("%s", GFTPUI_COMMON_COLOR_DEFAULT);
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
114
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
115 if (utf8_str != NULL)
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
116 g_free (utf8_str);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
117 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
118
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
119
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
120 char *
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
121 gftp_text_ask_question (const char *question, int echo, char *buf, size_t size)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
122 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
123 struct termios term, oldterm;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
124 sigset_t sig, sigsave;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
125 char *pos, *termname;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
126 FILE *infd;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
127
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
128 if (!echo)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
129 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
130 sigemptyset (&sig);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
131 sigaddset (&sig, SIGINT);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
132 sigaddset (&sig, SIGTSTP);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
133 sigprocmask (SIG_BLOCK, &sig, &sigsave);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
134
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
135 termname = ctermid (NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
136 if ((infd = fopen (termname, "r+")) == NULL)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
137 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
138
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
139 gftp_text_log (gftp_logging_error, NULL,
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
140 _("Cannot open controlling terminal %s\n"), termname);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
141 return (NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
142 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
143
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
144 tcgetattr (0, &term);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
145 oldterm = term;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
146 term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
147 tcsetattr (fileno (infd), TCSAFLUSH, &term);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
148 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
149 else
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
150 infd = stdin;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
151
356
7cb3327f96f7 2003-1-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 354
diff changeset
152 printf ("%s%s%s ", GFTPUI_COMMON_COLOR_BLUE, question, GFTPUI_COMMON_COLOR_DEFAULT);
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
153
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
154 if (fgets (buf, size, infd) == NULL)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
155 return (NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
156 buf[size - 1] = '\0';
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
157
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
158 if (!echo)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
159 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
160 printf ("\n");
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
161 tcsetattr (fileno (infd), TCSAFLUSH, &oldterm);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
162 fclose (infd);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
163 sigprocmask (SIG_SETMASK, &sigsave, NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
164 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
165
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
166 for (pos = buf + strlen (buf) - 1; *pos == ' ' || *pos == '\r' ||
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
167 *pos == '\n'; pos--);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
168 *(pos+1) = '\0';
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
169
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
170 for (pos = buf; *pos == ' '; pos++);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
171 if (*pos == '\0')
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
172 return (NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
173
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
174 return (pos);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
175 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
176
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
177
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
178 int
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
179 main (int argc, char **argv)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
180 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
181 char *startup_directory;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
182 #if HAVE_LIBREADLINE
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
183 char *tempstr, prompt[20];
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
184 #else
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
185 char tempstr[512];
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
186 #endif
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
187
374
d207b8241e96 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
188 gftpui_common_init (&argc, &argv, gftp_text_log);
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
189
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
190 /* SSH doesn't support reading the password with askpass via the command
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
191 line */
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
192
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
193 gftp_text_remreq = gftp_request_new ();
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
194 gftp_set_request_option (gftp_text_remreq, "ssh_use_askpass",
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
195 GINT_TO_POINTER(0));
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
196 gftp_set_request_option (gftp_text_remreq, "sshv2_use_sftp_subsys",
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
197 GINT_TO_POINTER(0));
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
198 gftp_text_remreq->logging_function = gftp_text_log;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
199
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
200 gftp_text_locreq = gftp_request_new ();
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
201 gftp_set_request_option (gftp_text_locreq, "ssh_use_askpass",
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
202 GINT_TO_POINTER(0));
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
203 gftp_set_request_option (gftp_text_locreq, "sshv2_use_sftp_subsys",
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
204 GINT_TO_POINTER(0));
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
205
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
206 gftp_text_locreq->logging_function = gftp_text_log;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
207 if (gftp_protocols[GFTP_LOCAL_NUM].init (gftp_text_locreq) == 0)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
208 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
209 gftp_lookup_request_option (gftp_text_locreq, "startup_directory",
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
210 &startup_directory);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
211 if (*startup_directory != '\0')
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
212 gftp_set_directory (gftp_text_locreq, startup_directory);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
213
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
214 gftp_connect (gftp_text_locreq);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
215 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
216
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
217 gftpui_common_about (gftp_text_log, NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
218 gftp_text_log (gftp_logging_misc, NULL, "\n");
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
219
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
220 /* FIXME
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
221 if (argc == 3 && strcmp (argv[1], "-d") == 0)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
222 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
223 if ((pos = strrchr (argv[2], '/')) != NULL)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
224 *pos = '\0';
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
225 gftp_text_open (gftp_text_remreq, argv[2], NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
226
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
227 if (pos != NULL)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
228 *pos = '/';
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
229
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
230 gftp_text_mget_file (gftp_text_remreq, pos + 1, NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
231 exit (0);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
232 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
233 else if (argc == 2)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
234 gftp_text_open (gftp_text_remreq, argv[1], NULL);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
235 */
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
236
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
237 #if HAVE_LIBREADLINE
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
238 g_snprintf (prompt, sizeof (prompt), "%sftp%s> ", GFTPUI_COMMON_COLOR_BLUE, GFTPUI_COMMON_COLOR_DEFAULT);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
239 while ((tempstr = readline (prompt)))
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
240 {
374
d207b8241e96 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
241 if (gftpui_common_process_command (NULL, gftp_text_locreq,
d207b8241e96 2003-1-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 356
diff changeset
242 NULL, gftp_text_remreq, tempstr) == 0)
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
243 break;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
244
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
245 add_history (tempstr);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
246 free (tempstr);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
247 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
248 #else
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
249 printf ("%sftp%s> ", GFTPUI_COMMON_COLOR_BLUE, GFTPUI_COMMON_COLOR_DEFAULT);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
250 while (fgets (tempstr, sizeof (tempstr), stdin) != NULL)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
251 {
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
252 if (gftpui_common_process_command (tempstr) == 0)
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
253 break;
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
254
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
255 printf ("%sftp%s> ", GFTPUI_COMMON_COLOR_BLUE, GFTPUI_COMMON_COLOR_DEFAULT);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
256 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
257 #endif
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
258
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
259 return (0);
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
260 }
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
261
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
262 #if 0
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
263 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
264 gftp_text_open (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
265 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
266 char tempstr[255], *pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
267
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
268 if (GFTP_IS_CONNECTED (request))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
269 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
270 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
271 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
272
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
273 if (*command == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
274 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
275 gftp_text_log (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
276 _("usage: open [[ftp://][user:pass@]ftp-site[:port][/directory]]\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
277 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
278 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
279
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
280 if (gftp_parse_url (request, command) < 0)
173
4c288d05b26a 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 169
diff changeset
281 return (1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
282
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 166
diff changeset
283 if (request->need_userpass)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
284 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 166
diff changeset
285 if (request->username == NULL || *request->username == '\0')
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
286 {
166
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
287 if ((pos = gftp_text_ask_question ("Username [anonymous]", 1, tempstr,
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
288 sizeof (tempstr))) != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
289 {
166
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
290 gftp_set_username (request, pos);
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 166
diff changeset
291 gftp_set_password (request, NULL);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
292 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
293 }
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 166
diff changeset
294
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 166
diff changeset
295 if (request->username != NULL &&
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 166
diff changeset
296 strcmp (request->username, "anonymous") != 0 &&
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 166
diff changeset
297 (request->password == NULL || *request->password == '\0'))
166
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
298 {
169
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 166
diff changeset
299 if ((pos = gftp_text_ask_question ("Password", 0, tempstr,
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 166
diff changeset
300 sizeof (tempstr))) == NULL)
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 166
diff changeset
301 return (1);
d40f9db52cdf 2003-6-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 166
diff changeset
302 gftp_set_password (request, pos);
166
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
303 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
304 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
305
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
306 gftp_connect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
307 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
308 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
309
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
310
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
311 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
312 gftp_text_mget_file (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
313 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
314 gftp_transfer * transfer;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
315 gftp_file * fle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
316
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
317 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
318 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
319 gftp_text_log (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
320 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
321 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
322 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
323
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
324 if (*command == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
325 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
326 gftp_text_log (gftp_logging_error, request,
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
327 _("usage: mget <filespec>\n"));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
328 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
329 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
330
129
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
331 transfer = gftp_tdata_new ();
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
332 transfer->fromreq = gftp_text_remreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
333 transfer->toreq = gftp_text_locreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
334
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
335 /* FIXME - ask whether to resume/skip/overwrite */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
336 if (gftp_list_files (transfer->fromreq) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
337 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
338 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
339 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
340 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
341 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
342 fle = g_malloc0 (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
343 while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
344 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
345 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
346 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
347 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
348 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
349 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
350 transfer->files = g_list_append (transfer->files, fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
351 fle = g_malloc (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
352 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
353 g_free (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
354 gftp_end_transfer (transfer->fromreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
355
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
356 if (transfer->files == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
357 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
358 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
359 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
360 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
361 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
362
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
363 if (gftp_get_all_subdirs (transfer, NULL) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
364 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
365 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
366 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
367 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
368 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
369
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
370 if (transfer->files == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
371 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
372 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
373 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
374 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
375 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
376
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
377 gftp_text_transfer_files (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
378 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
379 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
380 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
382
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
383
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
384 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
385 gftp_text_mput_file (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
386 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
387 gftp_transfer * transfer;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
388 gftp_file * fle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
389
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
390 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
391 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
392 gftp_text_log (gftp_logging_error, request,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
393 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
394 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
395 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
396
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
397 if (*command == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
398 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
399 gftp_text_log (gftp_logging_error, request,
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
400 _("usage: mput <filespec>\n"));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
401 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
402 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
403
129
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
404 transfer = gftp_tdata_new ();
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
405 transfer->fromreq = gftp_text_locreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
406 transfer->toreq = gftp_text_remreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
407
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
408 if (gftp_list_files (transfer->fromreq) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
409 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
410 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
411 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
412 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
413 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
414 fle = g_malloc (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
415 while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
416 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
417 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
418 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
419 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
420 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
421 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
422 transfer->files = g_list_append (transfer->files, fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
423 fle = g_malloc (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
424 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
425 g_free (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
426 gftp_end_transfer (transfer->fromreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
427
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
428 if (transfer->files == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
429 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
430 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
431 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
432 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
433 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
434
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
435 if (gftp_get_all_subdirs (transfer, NULL) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
436 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
437 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
438 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
439 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
440 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
441
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
442 if (transfer->files == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
443 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
444 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
445 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
446 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
447 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
448
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
449 gftp_text_transfer_files (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
450 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
451 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
452 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
453 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
454
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
455
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
456 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
457 gftp_text_transfer_files (gftp_transfer * transfer)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
458 {
327
98487556a058 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
459 int i, j, sw, tot;
98487556a058 2003-12-4 Brian Masney <masneyb@gftp.org>
masneyb
parents: 303
diff changeset
460 intptr_t preserve_permissions;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
461 char buf[8192], *progress = "|/-\\";
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
462 struct timeval updatetime;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
463 long fromsize, total;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
464 gftp_file * curfle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
465 ssize_t num_read;
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
466 mode_t mode;
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
467
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
468 gftp_lookup_request_option (transfer->fromreq, "preserve_permissions",
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
469 &preserve_permissions);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
470
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
471 for (transfer->curfle = transfer->files;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
472 transfer->curfle != NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
473 transfer->curfle = transfer->curfle->next)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
474 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
475 curfle = transfer->curfle->data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
476 if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
477 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
478
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
479 if (curfle->isdir && transfer->toreq->mkdir != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
480 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
481 transfer->toreq->mkdir (transfer->toreq, curfle->destfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
482 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
483 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
484
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
485 transfer->curtrans = curfle->startsize;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
486 fromsize = gftp_transfer_file (transfer->fromreq, curfle->file, -1,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
487 curfle->startsize, transfer->toreq, curfle->destfile,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
488 -1, curfle->startsize);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
489 if (fromsize < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
490 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
491
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
492 gettimeofday (&transfer->starttime, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
493 memcpy (&transfer->lasttime, &transfer->starttime,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
494 sizeof (transfer->lasttime));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
495 memset (&updatetime, 0, sizeof (updatetime));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
496
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
497 total = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
498 i = 0;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
499 num_read = -1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
500 while (!cancel && (num_read = gftp_get_next_file_chunk (transfer->fromreq,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
501 buf, sizeof (buf))) > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
502 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
503 printf ("\r%c ", progress[i++]);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
504 fflush (stdout);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
505 if (progress[i] == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
506 i = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
507
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
508 total += num_read;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
509 gftp_calc_kbs (transfer, num_read);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
510 if (transfer->lasttime.tv_sec - updatetime.tv_sec >= 1 || total >= fromsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
511 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
512 sw = gftp_text_get_win_size () - 20;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
513 tot = (float) total / (float) fromsize * (float) sw;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
514
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
515 if (tot > sw)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
516 tot = sw;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
517 printf ("[");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
518 for (j=0; j<tot; j++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
519 printf ("=");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
520 for (j=0; j<sw-tot; j++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
521 printf (" ");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
522 printf ("] @ %.2fKB/s", transfer->kbs);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
523 fflush (stdout);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
524 memcpy (&updatetime, &transfer->lasttime, sizeof (updatetime));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
525 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
526
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
527 if (gftp_put_next_file_chunk (transfer->toreq, buf, num_read) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
528 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
529 num_read = -1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
530 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
531 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
532 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
533 printf ("\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
534
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
535 if (num_read < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
536 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
537 gftp_text_log (gftp_logging_misc, transfer->fromreq,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
538 _("Could not download %s\n"), curfle->file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
539 gftp_disconnect (transfer->fromreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
540 gftp_disconnect (transfer->toreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
541 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
542 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
543 {
186
13ca1defdc75 2003-6-16 Brian Masney <masneyb@gftp.org>
masneyb
parents: 182
diff changeset
544 gftp_text_log (gftp_logging_misc, transfer->fromreq,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
545 _("Successfully transferred %s\n"), curfle->file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
546 gftp_end_transfer (transfer->fromreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
547 gftp_end_transfer (transfer->toreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
548 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
549
182
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
550 if (!curfle->is_fd && preserve_permissions)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
551 {
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
552 if (curfle->attribs)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
553 {
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
554 mode = gftp_parse_attribs (curfle->attribs);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
555 if (mode != 0)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
556 gftp_chmod (transfer->toreq, curfle->destfile, mode);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
557 }
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
558
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
559 if (curfle->datetime != 0)
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
560 gftp_set_file_time (transfer->toreq, curfle->destfile,
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
561 curfle->datetime);
33b394ebba68 2003-6-15 Brian Masney <masneyb@gftp.org>
masneyb
parents: 179
diff changeset
562 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
563 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
564 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
565 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
566
341
eedc2c5727fa 2003-12-28 Brian Masney <masneyb@gftp.org>
masneyb
parents: 327
diff changeset
567 #endif