annotate src/text/gftp-text.c @ 166:a4bf947e9e22

2003-5-27 Brian Masney <masneyb@gftp.org> * Makefile.am configure.in autogen.sh - build fixes * src/text/gftp-text.c - if the protocol we are connecting to doesn't need a username/password, don't prompt the user for one
author masneyb
date Tue, 27 May 2003 18:03:20 +0000
parents 5c952c5cb438
children d40f9db52cdf
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 static volatile int cancel = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
26 static int configuration_changed = 0,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
27 number_commands = 30;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
28
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
29 struct _gftp_text_methods gftp_text_methods[] = {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
30 {N_("about"), 2, gftp_text_about, NULL,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
31 N_("Shows gFTP information"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
32 {N_("ascii"), 2, gftp_text_ascii, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
33 N_("Sets the current file transfer mode to Ascii (only for FTP)"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
34 {N_("binary"), 1, gftp_text_binary, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
35 N_("Sets the current file transfer mode to Binary (only for FTP)"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
36 {N_("cd"), 2, gftp_text_cd, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
37 N_("Changes the remote working directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
38 {N_("chdir"), 3, gftp_text_cd, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
39 N_("Changes the remote working directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
40 {N_("chmod"), 3, gftp_text_chmod, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
41 N_("Changes the permissions of a remote file"), NULL},
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
42 {N_("clear"), 3, gftp_text_clear, NULL,
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
43 N_("Available options: cache"), gftp_text_clear_show_subhelp},
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
44 {N_("close"), 3, gftp_text_close, &gftp_text_remreq,
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
45 N_("Disconnects from the remote site"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
46 {N_("delete"), 1, gftp_text_delete, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
47 N_("Removes a remote file"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
48 {N_("get"), 1, gftp_text_mget_file, NULL,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
49 N_("Downloads remote file(s)"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
50 {N_("help"), 1, gftp_text_help, NULL,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
51 N_("Shows this help screen"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
52 {N_("lcd"), 3, gftp_text_cd, &gftp_text_locreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
53 N_("Changes the local working directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
54 {N_("lchdir"), 4, gftp_text_cd, &gftp_text_locreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
55 N_("Changes the local working directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
56 {N_("lchmod"), 4, gftp_text_chmod, &gftp_text_locreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
57 N_("Changes the permissions of a local file"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
58 {N_("ldelete"), 2, gftp_text_delete, &gftp_text_locreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
59 N_("Removes a local file"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
60 {N_("lls"), 2, gftp_text_ls, &gftp_text_locreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
61 N_("Shows the directory listing for the current local directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
62 {N_("lmkdir"), 2, gftp_text_mkdir, &gftp_text_locreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
63 N_("Creates a local directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
64 {N_("lpwd"), 2, gftp_text_pwd, &gftp_text_locreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
65 N_("Show current local directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
66 {N_("lrename"), 3, gftp_text_rename, &gftp_text_locreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
67 N_("Rename a local file"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
68 {N_("lrmdir"), 3, gftp_text_rmdir, &gftp_text_locreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
69 N_("Remove a local directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
70 {N_("ls"), 2, gftp_text_ls, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
71 N_("Shows the directory listing for the current remote directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
72 {N_("mget"), 2, gftp_text_mget_file, NULL,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
73 N_("Downloads remote file(s)"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
74 {N_("mkdir"), 2, gftp_text_mkdir, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
75 N_("Creates a remote directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
76 {N_("mput"), 2, gftp_text_mput_file, NULL,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
77 N_("Uploads local file(s)"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
78 {N_("open"), 1, gftp_text_open, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
79 N_("Opens a connection to a remote site"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
80 {N_("put"), 2, gftp_text_mput_file, NULL,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
81 N_("Uploads local file(s)"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
82 {N_("pwd"), 2, gftp_text_pwd, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
83 N_("Show current remote directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
84 {N_("quit"), 1, gftp_text_quit, NULL,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
85 N_("Exit from gFTP"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
86 {N_("rename"), 2, gftp_text_rename, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
87 N_("Rename a remote file"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
88 {N_("rmdir"), 2, gftp_text_rmdir, &gftp_text_remreq,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
89 N_("Remove a remote directory"), NULL},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
90 {N_("set"), 1, gftp_text_set, NULL,
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
91 N_("Show configuration file variables. You can also set variables by set var=val"), gftp_text_set_show_subhelp},
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
92 {NULL, 0, NULL, NULL, NULL}};
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
93
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
94 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
95 main (int argc, char **argv)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
96 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
97 char *pos, *stpos, *startup_directory;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
98 gftp_request * request;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
99 size_t len, cmdlen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
100 int i;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
101 #ifdef HAVE_LIBREADLINE
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
102 char *tempstr, prompt[20];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
103 #else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
104 char tempstr[512];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
105 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
106
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
107 #ifdef HAVE_GETTEXT
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
108 setlocale (LC_ALL, "");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
109 bindtextdomain ("gftp", LOCALE_DIR);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
110 textdomain ("gftp");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
111 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
112
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
113 signal (SIGCHLD, sig_child);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
114 signal (SIGPIPE, SIG_IGN);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
115
124
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
116 gftp_read_config_file (SHARE_DIR);
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
117
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
118 if (gftp_parse_command_line (&argc, &argv) != 0)
65048c959029 2003-4-6 Brian Masney <masneyb@gftp.org>
masneyb
parents: 122
diff changeset
119 exit (0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
120
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
121 /* SSH doesn't support reading the password with askpass via the command
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
122 line */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
123
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
124 gftp_text_remreq = gftp_request_new ();
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
125 gftp_set_request_option (gftp_text_remreq, "ssh_use_askpass",
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
126 GINT_TO_POINTER(0));
143
5c952c5cb438 2003-4-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 131
diff changeset
127 gftp_set_request_option (gftp_text_remreq, "sshv2_use_sftp_subsys",
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
128 GINT_TO_POINTER(0));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
129 gftp_text_remreq->logging_function = gftp_text_log;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
130
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
131 gftp_text_locreq = gftp_request_new ();
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
132 gftp_set_request_option (gftp_text_locreq, "ssh_use_askpass",
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
133 GINT_TO_POINTER(0));
143
5c952c5cb438 2003-4-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 131
diff changeset
134 gftp_set_request_option (gftp_text_locreq, "sshv2_use_sftp_subsys",
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
135 GINT_TO_POINTER(0));
143
5c952c5cb438 2003-4-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 131
diff changeset
136
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
137 gftp_text_locreq->logging_function = gftp_text_log;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
138 gftp_protocols[GFTP_LOCAL_NUM].init (gftp_text_locreq);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
139
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
140 gftp_lookup_request_option (gftp_text_locreq, "startup_directory",
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
141 &startup_directory);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
142 if (*startup_directory != '\0')
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
143 gftp_set_directory (gftp_text_locreq, startup_directory);
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
144
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
145 gftp_connect (gftp_text_locreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
146
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
147 gftp_text_log (gftp_logging_misc, NULL, "%s, Copyright (C) 1998-2003 Brian Masney <", gftp_version);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
148 gftp_text_log (gftp_logging_recv, NULL, "masneyb@gftp.org");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
149 gftp_text_log (gftp_logging_misc, NULL, _(">.\nIf you have any questions, comments, or suggestions about this program, please feel free to email them to me. You can always find out the latest news about gFTP from my website at http://www.gftp.org/\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
150 gftp_text_log (gftp_logging_misc, NULL, "\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
151 gftp_text_log (gftp_logging_misc, NULL, _("gFTP comes with ABSOLUTELY NO WARRANTY; for details, see the COPYING file. This is free software, and you are welcome to redistribute it under certain conditions; for details, see the COPYING file\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
152 gftp_text_log (gftp_logging_misc, NULL, "\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
153
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
154 if (argc == 3 && strcmp (argv[1], "-d") == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
155 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
156 if ((pos = strrchr (argv[2], '/')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
157 *pos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
158 gftp_text_open (gftp_text_remreq, argv[2], NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
159
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
160 if (pos != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
161 *pos = '/';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
162
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
163 gftp_text_mget_file (gftp_text_remreq, pos + 1, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
164 exit (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
165 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
166 else if (argc == 2)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
167 gftp_text_open (gftp_text_remreq, argv[1], NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
168
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
169 #ifdef HAVE_LIBREADLINE
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
170 g_snprintf (prompt, sizeof (prompt), "%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
171 while ((tempstr = readline (prompt)))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
172 #else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
173 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
174 while (fgets (tempstr, sizeof (tempstr), stdin) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
175 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
176 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
177 len = strlen (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
178 if (tempstr[len - 1] == '\n')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
179 tempstr[--len] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
180 if (tempstr[len - 1] == '\r')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
181 tempstr[--len] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
182
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
183 for (stpos = tempstr; *stpos == ' '; stpos++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
184
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
185 for (pos = tempstr + len - 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
186 (*pos == ' ' || *pos == '\t') && pos > tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
187 pos--)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
188 *pos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
189
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
190 if (*stpos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
191 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
192 #ifndef HAVE_LIBREADLINE
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
193 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
194 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
195 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
196 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
197
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
198 #ifdef HAVE_LIBREADLINE
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
199 add_history (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
200 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
201
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
202 if ((pos = strchr (stpos, ' ')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
203 *pos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
204 cmdlen = strlen (stpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
205
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
206 for (i=0; gftp_text_methods[i].command != NULL; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
207 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
208 if (strcmp (gftp_text_methods[i].command, stpos) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
209 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
210 else if (cmdlen >= gftp_text_methods[i].minlen &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
211 strncmp (gftp_text_methods[i].command, stpos, cmdlen) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
212 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
213 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
214
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
215 if (pos != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
216 pos++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
217 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
218 pos = "";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
219
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
220 if (gftp_text_methods[i].command != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
221 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
222 if (gftp_text_methods[i].request != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
223 request = *gftp_text_methods[i].request;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
224 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
225 request = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
226
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
227 if (gftp_text_methods[i].func (request, pos, NULL) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
228 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
229 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
230 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
231 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
232 _("Error: Command not recognized\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
233
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
234 #ifdef HAVE_LIBREADLINE
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
235 free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
236 #else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
237 printf ("%sftp%s> ", COLOR_BLUE, COLOR_DEFAULT);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
238 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
239 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
240
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
241 if (gftp_logfd != NULL)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
242 fclose (gftp_logfd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
243 gftp_text_quit (NULL, NULL, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
244
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
245 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
246 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
247
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
248
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
249 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
250 gftp_text_log (gftp_logging_level level, void *ptr, const char *string, ...)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
251 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
252 char tempstr[512], *stpos, *endpos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
253 va_list argp;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
254 int sw;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
255
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
256 g_return_if_fail (string != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
257
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
258 switch (level)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
259 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
260 case gftp_logging_send:
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
261 printf ("%s", COLOR_GREEN);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
262 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
263 case gftp_logging_recv:
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
264 printf ("%s", COLOR_YELLOW);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
265 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
266 case gftp_logging_error:
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
267 printf ("%s", COLOR_RED);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
268 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
269 default:
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
270 printf ("%s", COLOR_DEFAULT);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
271 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
272 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
273
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
274 va_start (argp, string);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
275 g_vsnprintf (tempstr, sizeof (tempstr), string, argp);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
276 va_end (argp);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
277
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
278 if (gftp_logfd != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
279 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
280 fwrite (tempstr, 1, strlen (tempstr), gftp_logfd);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
281 if (ferror (gftp_logfd))
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
282 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
283 fclose (gftp_logfd);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
284 gftp_logfd = NULL;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
285 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
286 else
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
287 fflush (gftp_logfd);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
288 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
289
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
290 sw = gftp_text_get_win_size ();
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
291 stpos = tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
292 endpos = tempstr + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
293 do
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
294 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
295 if (strlen (stpos) <= sw)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
296 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
297 printf ("%s", stpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
298 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
299 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
300 for (endpos = stpos + sw - 1; *endpos != ' ' && endpos > stpos; endpos--);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
301 if (endpos != stpos)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
302 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
303 *endpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
304 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
305 printf ("%s\n", stpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
306 stpos = endpos + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
307 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
308 while (stpos != endpos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
309
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
310 printf ("%s", COLOR_DEFAULT);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
311 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
312
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
313
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
314 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
315 gftp_text_open (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
316 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
317 char tempstr[255], *pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
318
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
319 if (GFTP_IS_CONNECTED (request))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
320 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
321 gftp_disconnect (request);
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 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
326 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
327 _("usage: open [[ftp://][user:pass@]ftp-site[:port][/directory]]\n"));
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
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
331 if (gftp_parse_url (request, command) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
332 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
333 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
334 _("Could not parse URL %s\n"), command);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
335 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
336 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
337
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
338 if (request->username == NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
339 {
166
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
340 if (request->need_userpass)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
341 {
166
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
342 if ((pos = gftp_text_ask_question ("Username [anonymous]", 1, tempstr,
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
343 sizeof (tempstr))) != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
344 {
166
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
345 gftp_set_username (request, pos);
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
346 if (request->password)
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
347 {
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
348 g_free (request->password);
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
349 request->password = NULL;
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
350 }
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
351 }
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
352 else
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
353 gftp_set_username (request, "anonymous");
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
354
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
355 if (strcmp (request->username, "anonymous") != 0 &&
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
356 (request->password == NULL || *request->password == '\0'))
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
357 {
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
358 if ((pos = gftp_text_ask_question ("Password", 0, tempstr,
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
359 sizeof (tempstr))) == NULL)
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
360 return (1);
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
361 gftp_set_password (request, pos);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
362 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
363 }
67
aa971a4bb16f 2002-11-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
364 else
166
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
365 {
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
366 request->username = g_strdup ("");
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
367 if (request->password != NULL)
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
368 g_free (request->password);
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
369 request->password = g_strdup ("");
a4bf947e9e22 2003-5-27 Brian Masney <masneyb@gftp.org>
masneyb
parents: 143
diff changeset
370 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
371 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
372
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
373
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
374 gftp_connect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
375 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
376 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
377
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
378
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
379 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
380 gftp_text_close (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
382 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
383 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
384 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
385
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
386
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
387 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
388 gftp_text_about (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
389 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
390 char *str;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
391
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
392 gftp_text_log (gftp_logging_misc, NULL,
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
393 "%s. Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org>\n",
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
394 gftp_version);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
395
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
396 str = _("Translated by");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
397 if (strcmp (str, "Translated by") != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
398 gftp_text_log (gftp_logging_misc, NULL, "%s\n", str);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
399 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
400 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
401
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
402
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
403 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
404 gftp_text_quit (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
405 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
406 gftp_clear_cache_files ();
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
407 if (configuration_changed)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
408 gftp_write_config_file ();
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
409 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
410 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
411
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
412
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
413 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
414 gftp_text_pwd (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
415 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
416 if (!GFTP_IS_CONNECTED (request))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
417 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
418 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
419 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
420 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
421 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
422 gftp_text_log (gftp_logging_misc, NULL, "%s\n", request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
423 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
424 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
425
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
426
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
427 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
428 gftp_text_cd (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
429 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
430 char *newdir = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
431
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
432 if (!GFTP_IS_CONNECTED (request))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
433 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
434 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
435 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
436 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
437 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
438 else if (*command == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
439 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
440 gftp_text_log (gftp_logging_error, NULL, _("usage: chdir <directory>\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
441 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
442 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
443 else if (request->protonum == GFTP_LOCAL_NUM &&
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
444 (newdir = expand_path (command)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
445 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
446 gftp_text_log (gftp_logging_error, NULL, _("usage: chdir <directory>\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
447 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
448 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
449
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
450 gftp_set_directory (request, newdir != NULL ? newdir : command);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
451
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
452 if (newdir != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
453 g_free (newdir);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
454
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
455 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
456 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
457
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
458
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
459 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
460 gftp_text_mkdir (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
461 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
462 if (!GFTP_IS_CONNECTED (request))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
463 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
464 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
465 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
466 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
467 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
468
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
469 if (*command == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
470 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
471 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
472 _("usage: mkdir <new directory>\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
473 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
474 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
475 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
476 gftp_make_directory (request, command);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
477 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
478 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
479 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
480
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
481
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
482 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
483 gftp_text_rmdir (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
484 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
485 if (!GFTP_IS_CONNECTED (request))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
486 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
487 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
488 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
489 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
490 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
491
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
492 if (*command == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
493 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
494 gftp_text_log (gftp_logging_error, NULL, _("usage: rmdir <directory>\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
495 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
496 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
497 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
498 gftp_remove_directory (request, command);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
499 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
500 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
501 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
502
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
503
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
504 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
505 gftp_text_delete (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
506 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
507 if (!GFTP_IS_CONNECTED (request))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
508 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
509 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
510 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
511 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
512 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
513
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
514 if (*command == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
515 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
516 gftp_text_log (gftp_logging_error, NULL,_("usage: delete <file>\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
517 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
518 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
519 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
520 gftp_remove_file (request, command);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
521 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
522 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
523 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
524
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
525
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
526 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
527 gftp_text_rename (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
528 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
529 char *pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
530
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
531 if (!GFTP_IS_CONNECTED (request))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
532 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
533 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
534 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
535 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
536 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
537
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
538 if ((pos = strchr (command, ' ')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
539 *pos++ = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
540
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
541 if (*command == '\0' || pos == NULL || *pos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
542 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
543 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
544 _("usage: rename <old name> <new name>\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
545 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
546 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
547 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
548 gftp_rename_file (request, command, pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
549 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
550 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
551 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
552
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
553
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
554 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
555 gftp_text_chmod (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
556 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
557 char *pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
558
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
559 if (!GFTP_IS_CONNECTED (request))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
560 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
561 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
562 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
563 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
564 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
565
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
566 if ((pos = strchr (command, ' ')) != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
567 *pos++ = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
568
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
569 if (*command == '\0' || pos == NULL || *pos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
570 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
571 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
572 _("usage: chmod <mode> <file>\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
573 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
574 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
575 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
576 gftp_chmod (request, pos, strtol (command, NULL, 10));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
577 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
578 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
579 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
580
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
581
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
582 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
583 gftp_text_ls (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
584 {
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
585 GList * files, * templist, * delitem;
131
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
586 char *color, *filespec, *tempstr;
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
587 int sortcol, sortasds;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
588 gftp_file * fle;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
589 time_t curtime;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
590
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
591 time (&curtime);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
592 if (!GFTP_IS_CONNECTED (request))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
593 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
594 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
595 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
596 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
597 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
598
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
599 filespec = *command != '\0' ? command : NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
600 if (gftp_list_files (request) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
601 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
602
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
603 files = NULL;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
604 fle = g_malloc0 (sizeof (*fle));
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
605 while (gftp_get_next_file (request, NULL, fle) > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
606 {
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
607 if (strcmp (fle->file, ".") == 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
608 {
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
609 gftp_file_destroy (fle);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
610 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
611 }
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
612 files = g_list_prepend (files, fle);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
613 fle = g_malloc0 (sizeof (*fle));
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
614 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
615 g_free (fle);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
616
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
617 if (files == NULL)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
618 return (1);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
619
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
620 if (request == gftp_text_locreq)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
621 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
622 gftp_lookup_request_option (request, "local_sortcol", &sortcol);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
623 gftp_lookup_request_option (request, "local_sortasds", &sortasds);
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
624 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
625 else
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
626 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
627 gftp_lookup_request_option (request, "remote_sortcol", &sortcol);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
628 gftp_lookup_request_option (request, "remote_sortasds", &sortasds);
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
629 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
630
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
631 files = gftp_sort_filelist (files, sortcol, sortasds);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
632 delitem = NULL;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
633 for (templist = files; templist != NULL; templist = templist->next)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
634 {
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
635 if (delitem != NULL)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
636 {
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
637 fle = delitem->data;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
638 gftp_file_destroy (fle);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
639 g_free (fle);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
640 delitem = NULL;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
641 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
642
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
643 fle = templist->data;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
644
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
645 if (*fle->attribs == 'd')
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
646 color = COLOR_BLUE;
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
647 else if (*fle->attribs == 'l')
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
648 color = COLOR_WHITE;
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
649 else if (strchr (fle->attribs, 'x') != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
650 color = COLOR_GREEN;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
651 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
652 color = COLOR_DEFAULT;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
653
131
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
654 tempstr = gftp_gen_ls_string (fle, color, COLOR_DEFAULT);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
655 printf ("%s\n", tempstr);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
656 g_free (tempstr);
c77f85763e28 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 129
diff changeset
657
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
658 delitem = templist;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
659 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
660 gftp_end_transfer (request);
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
661
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
662 if (delitem != NULL)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
663 {
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
664 fle = delitem->data;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
665 gftp_file_destroy (fle);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
666 g_free (fle);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
667 delitem = NULL;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
668 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
669
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
670 if (files != NULL)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
671 g_list_free (files);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
672
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
673 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
674 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
675
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
676
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
677 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
678 gftp_text_binary (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
679 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
680 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
681 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
682 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
683 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
684 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
685 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
686
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
687 gftp_set_request_option (gftp_text_remreq, "ascii_transfers",
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
688 GINT_TO_POINTER(0));
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
689 gftp_set_request_option (gftp_text_locreq, "ascii_transfers",
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
690 GINT_TO_POINTER(0));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
691 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
692 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
693
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
694
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
695 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
696 gftp_text_ascii (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
697 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
698 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
699 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
700 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
701 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
702 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
703 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
704
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
705 gftp_set_request_option (gftp_text_remreq, "ascii_transfers",
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
706 GINT_TO_POINTER(1));
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
707 gftp_set_request_option (gftp_text_locreq, "ascii_transfers",
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
708 GINT_TO_POINTER(1));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
709 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
710 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
711
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
712
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
713 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
714 gftp_text_mget_file (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
715 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
716 gftp_transfer * transfer;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
717 gftp_file * fle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
718
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
719 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
720 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
721 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
722 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
723 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
724 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
725
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
726 if (*command == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
727 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
728 gftp_text_log (gftp_logging_error, NULL, _("usage: mget <filespec>\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
729 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
730 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
731
129
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
732 transfer = gftp_tdata_new ();
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
733 transfer->fromreq = gftp_text_remreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
734 transfer->toreq = gftp_text_locreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
735 transfer->transfer_direction = GFTP_DIRECTION_DOWNLOAD;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
736
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
737 /* FIXME - ask whether to resume/skip/overwrite */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
738 if (gftp_list_files (transfer->fromreq) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
739 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
740 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
741 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
742 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
743 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
744 fle = g_malloc0 (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
745 while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
746 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
747 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
748 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
749 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
750 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
751 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
752 transfer->files = g_list_append (transfer->files, fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
753 fle = g_malloc (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
754 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
755 g_free (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
756 gftp_end_transfer (transfer->fromreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
757
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
758 if (transfer->files == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
759 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
760 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
761 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
762 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
763 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
764
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
765 if (gftp_get_all_subdirs (transfer, NULL) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
766 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
767 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
768 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
769 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
770 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
771
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
772 if (transfer->files == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
773 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
774 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
775 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
776 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
777 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
778
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
779 gftp_text_transfer_files (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
780 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
781 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
782 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
783 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
784
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
785
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
786 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
787 gftp_text_mput_file (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
788 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
789 gftp_transfer * transfer;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
790 gftp_file * fle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
791
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
792 if (!GFTP_IS_CONNECTED (gftp_text_remreq))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
793 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
794 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
795 _("Error: Not connected to a remote site\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
796 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
797 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
798
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
799 if (*command == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
800 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
801 gftp_text_log (gftp_logging_error, NULL, _("usage: mput <filespec>\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
802 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
803 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
804
129
fe0b21c006f6 2003-4-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 125
diff changeset
805 transfer = gftp_tdata_new ();
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
806 transfer->fromreq = gftp_text_locreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
807 transfer->toreq = gftp_text_remreq;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
808 transfer->transfer_direction = GFTP_DIRECTION_UPLOAD;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
809
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
810 if (gftp_list_files (transfer->fromreq) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
811 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
812 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
813 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
814 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
815 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
816 fle = g_malloc (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
817 while (gftp_get_next_file (transfer->fromreq, command, fle) > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
818 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
819 if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
820 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
821 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
822 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
823 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
824 transfer->files = g_list_append (transfer->files, fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
825 fle = g_malloc (sizeof (*fle));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
826 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
827 g_free (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
828 gftp_end_transfer (transfer->fromreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
829
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
830 if (transfer->files == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
831 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
832 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
833 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
834 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
835 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
836
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
837 if (gftp_get_all_subdirs (transfer, NULL) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
838 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
839 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
840 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
841 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
842 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
843
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
844 if (transfer->files == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
845 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
846 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
847 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
848 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
849 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
850
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
851 gftp_text_transfer_files (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
852 transfer->fromreq = transfer->toreq = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
853 free_tdata (transfer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
854 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
855 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
856
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
857
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
858 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
859 gftp_text_transfer_files (gftp_transfer * transfer)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
860 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
861 char buf[8192], *progress = "|/-\\";
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
862 struct timeval updatetime;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
863 long fromsize, total;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
864 gftp_file * curfle;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
865 int i, j, sw, tot;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
866 ssize_t num_read;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
867
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
868 for (transfer->curfle = transfer->files;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
869 transfer->curfle != NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
870 transfer->curfle = transfer->curfle->next)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
871 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
872 curfle = transfer->curfle->data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
873 if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
874 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
875
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
876 if (curfle->isdir && transfer->toreq->mkdir != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
877 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
878 transfer->toreq->mkdir (transfer->toreq, curfle->destfile);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
879 continue;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
880 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
881
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
882 transfer->curtrans = curfle->startsize;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
883 fromsize = gftp_transfer_file (transfer->fromreq, curfle->file, -1,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
884 curfle->startsize, transfer->toreq, curfle->destfile,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
885 -1, curfle->startsize);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
886 if (fromsize < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
887 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
888
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
889 gettimeofday (&transfer->starttime, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
890 memcpy (&transfer->lasttime, &transfer->starttime,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
891 sizeof (transfer->lasttime));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
892 memset (&updatetime, 0, sizeof (updatetime));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
893
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
894 total = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
895 i = 0;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
896 num_read = -1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
897 while (!cancel && (num_read = gftp_get_next_file_chunk (transfer->fromreq,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
898 buf, sizeof (buf))) > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
899 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
900 printf ("\r%c ", progress[i++]);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
901 fflush (stdout);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
902 if (progress[i] == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
903 i = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
904
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
905 total += num_read;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
906 gftp_calc_kbs (transfer, num_read);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
907 if (transfer->lasttime.tv_sec - updatetime.tv_sec >= 1 || total >= fromsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
908 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
909 sw = gftp_text_get_win_size () - 20;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
910 tot = (float) total / (float) fromsize * (float) sw;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
911
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
912 if (tot > sw)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
913 tot = sw;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
914 printf ("[");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
915 for (j=0; j<tot; j++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
916 printf ("=");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
917 for (j=0; j<sw-tot; j++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
918 printf (" ");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
919 printf ("] @ %.2fKB/s", transfer->kbs);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
920 fflush (stdout);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
921 memcpy (&updatetime, &transfer->lasttime, sizeof (updatetime));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
922 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
923
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
924 if (gftp_put_next_file_chunk (transfer->toreq, buf, num_read) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
925 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
926 num_read = -1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
927 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
928 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
929 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
930 printf ("\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
931
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
932 if (num_read < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
933 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
934 gftp_text_log (gftp_logging_misc, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
935 _("Could not download %s\n"), curfle->file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
936 gftp_disconnect (transfer->fromreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
937 gftp_disconnect (transfer->toreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
938 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
939 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
940 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
941 gftp_text_log (gftp_logging_misc, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
942 _("Successfully transferred %s\n"), curfle->file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
943 gftp_end_transfer (transfer->fromreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
944 gftp_end_transfer (transfer->toreq);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
945 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
946
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
947 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
948 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
949 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
950
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
951
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
952 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
953 gftp_text_help (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
954 {
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
955 int i, j, ele, numrows, numcols = 6, handled;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
956 char *pos;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
957
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
958 if (command != NULL && *command != '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
959 {
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
960 for (pos = command; *pos != ' ' && *pos != '\0'; pos++);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
961 if (*pos == ' ')
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
962 {
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
963 *pos++ = '\0';
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
964 if (*pos == '\0')
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
965 pos = NULL;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
966 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
967 else
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
968 pos = NULL;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
969
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
970 for (i=0; gftp_text_methods[i].command != NULL; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
971 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
972 if (strcmp (gftp_text_methods[i].command, command) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
973 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
974 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
975
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
976 if (gftp_text_methods[i].cmd_description != NULL)
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
977 {
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
978 if (pos != NULL && gftp_text_methods[i].subhelp_func != NULL)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
979 handled = gftp_text_methods[i].subhelp_func (pos);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
980 else
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
981 handled = 0;
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
982
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
983 if (!handled)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
984 printf ("%s\n", _(gftp_text_methods[i].cmd_description));
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
985 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
986 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
987 *command = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
988 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
989
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
990 if (command == NULL || *command == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
991 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
992 numrows = number_commands / numcols;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
993 if (number_commands % numcols != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
994 numrows++;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
995
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
996 printf (_("Supported commands:\n\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
997 for (i=0; i<numrows; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
998 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
999 printf (" ");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1000 for (j=0; j<numcols; j++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1001 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1002 ele = i + j * numrows;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1003 if (ele >= number_commands)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1004 break;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1005 printf ("%-10s", gftp_text_methods[ele].command);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1006 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1007 printf ("\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1008 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1009
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1010 printf ("\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1011 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1012 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1013 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1014
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1015
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1016 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1017 gftp_text_set (gftp_request * request, char *command, gpointer *data)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1018 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1019 gftp_config_vars * cv;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1020 char *pos, *backpos;
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1021 GList * templist;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1022 int i;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1023
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1024 if (command == NULL || *command == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1025 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1026 for (templist = gftp_options_list;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1027 templist != NULL;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1028 templist = templist->next)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1029 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1030 cv = templist->data;
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1031
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1032 for (i=0; cv[i].key != NULL; i++)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1033 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1034 if (!(cv[i].ports_shown & GFTP_PORT_TEXT))
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1035 continue;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1036
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1037 if (*cv[i].key == '\0' ||
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1038 gftp_option_types[cv[i].otype].write_function == NULL)
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1039 continue;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1040
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1041 printf ("%s = ", cv[i].key);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1042 gftp_option_types[cv[i].otype].write_function (&cv[i], stdout, 0);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1043 printf ("\n");
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1044 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1045 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1046 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1047 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1048 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1049 if ((pos = strchr (command, '=')) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1050 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1051 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1052 _("usage: set [variable = value]\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1053 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1054 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1055 *pos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1056
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1057 for (backpos = pos - 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1058 (*backpos == ' ' || *backpos == '\t') && backpos > command;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1059 backpos--)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1060 *backpos = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1061 for (++pos; *pos == ' ' || *pos == '\t'; pos++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1062
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1063 if ((cv = g_hash_table_lookup (gftp_global_options_htable, command)) == NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1064 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1065 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1066 _("Error: Variable %s is not a valid configuration variable.\n"), command);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1067 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1068 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1069
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1070 if (!(cv->ports_shown & GFTP_PORT_TEXT))
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1071 {
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1072 gftp_text_log (gftp_logging_error, NULL,
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1073 _("Error: Variable %s is not available in the text port of gFTP\n"), command);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1074 return (1);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1075 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1076
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1077 if (gftp_option_types[cv->otype].read_function != NULL)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1078 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1079 configuration_changed = 1;
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1080 gftp_option_types[cv->otype].read_function (pos, cv, 1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1081 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1082 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1083
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1084 return (1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1085 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1086
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1087
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1088 int
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1089 gftp_text_clear (gftp_request * request, char *command, gpointer *data)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1090 {
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1091 if (strcasecmp (command, "cache") == 0)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1092 gftp_clear_cache_files ();
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1093 else
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1094 gftp_text_log (gftp_logging_error, NULL, "Invalid argument\n");
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1095 return (1);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1096 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1097
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1098
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1099 char *
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1100 gftp_text_ask_question (const char *question, int echo, char *buf, size_t size)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1101 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1102 struct termios term, oldterm;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1103 sigset_t sig, sigsave;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1104 char *pos, *termname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1105 FILE *infd, *outfd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1106
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1107 if (!echo)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1108 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1109 sigemptyset (&sig);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1110 sigaddset (&sig, SIGINT);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1111 sigaddset (&sig, SIGTSTP);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1112 sigprocmask (SIG_BLOCK, &sig, &sigsave);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1113
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1114 termname = ctermid (NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1115 if ((infd = fopen (termname, "r+")) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1116 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1117
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1118 gftp_text_log (gftp_logging_error, NULL,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1119 "Cannot open controlling terminal %s\n", termname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1120 return (NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1121 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1122 outfd = infd;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1123
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1124 tcgetattr (0, &term);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1125 oldterm = term;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1126 term.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1127 tcsetattr (fileno (infd), TCSAFLUSH, &term);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1128 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1129 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1130 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1131 infd = stdin;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1132 outfd = stdout;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1133 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1134
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1135 fprintf (outfd, "%s%s%s: ", COLOR_BLUE, question, COLOR_DEFAULT);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1136
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1137 if (fgets (buf, size, infd) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1138 return (NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1139 buf[size - 1] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1140
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1141 if (!echo)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1142 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1143 fprintf (outfd, "\n");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1144 tcsetattr (fileno (infd), TCSAFLUSH, &oldterm);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1145 fclose (outfd);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1146 sigprocmask (SIG_SETMASK, &sigsave, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1147 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1148
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1149 for (pos = buf + strlen (buf) - 1; *pos == ' ' || *pos == '\r' ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1150 *pos == '\n'; pos--);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1151 *(pos+1) = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1152
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1153 for (pos = buf; *pos == ' '; pos++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1154 if (*pos == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1155 return (NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1156
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1157 return (pos);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1158 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1159
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1160
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1161 int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1162 gftp_text_get_win_size (void)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1163 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1164 struct winsize size;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1165 int ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1166
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1167 if (ioctl (0, TIOCGWINSZ, (char *) &size) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1168 ret = 80;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1169 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1170 ret = size.ws_col;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1171 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1172 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1173
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1174
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1175 void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1176 sig_child (int signo)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1177 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1178 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1179
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1180
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1181 int
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1182 gftp_text_set_show_subhelp (char *topic)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1183 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1184 gftp_config_vars * cv;
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1185
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1186 if ((cv = g_hash_table_lookup (gftp_global_options_htable, topic)) != NULL)
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1187 {
122
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1188 printf ("%s\n", cv->comment);
76e2b58a9440 2003-4-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 67
diff changeset
1189 return (1);
37
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1190 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1191
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1192 return (0);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1193 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1194
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1195
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1196 int
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1197 gftp_text_clear_show_subhelp (char *topic)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1198 {
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1199 if (strcmp (topic, "cache") == 0)
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1200 {
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1201 printf (_("Clear the directory cache\n"));
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1202 return (1);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1203 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1204
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1205 return (0);
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1206 }
5a178bd04ca5 2002-10-13 Brian Masney <masneyb@gftp.org>
masneyb
parents: 33
diff changeset
1207