annotate src/text/gftp-text.c @ 179:8d933999bba6

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