annotate src/text/gftp-text.c @ 129:fe0b21c006f6

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