# HG changeset patch # User masneyb # Date 1074944711 0 # Node ID 14da115b149bcc1dc26b999a07750608fb573bc9 # Parent 6b25e7a2ff20998a5f1ae07445c9cc401ff30e22 2003-1-23 Brian Masney * src/text/gftp-text.c src/uicommon/gftpui.c - added file transfer functions to the command line. * src/uicommon/gftpui_transfer.c src/uicommon/gftpui.h src/text/textui.c src/gtk/gtkui_transfer.c - added gftpui_{start,update,finish}_current_file_in_transfer() functions that will be called throughout the lifetime of a file transfer. Also, gftpui_start_transfer() that will be called whenever a file transfer is created * src/uicommon/gftpui.h src/uicommon/gftpui.c src/gtk/gftp-gtk.c src/gtk/transfer.c - added other_uidata and other_request arguments to all of the command line functions * lib/protocols.c lib/gftp.h - set the filespec argument to gftp_get_next_file to be a constant * lib/gftp.h - added tot_file_trans variable to gftp_transfer struct diff -r 6b25e7a2ff20 -r 14da115b149b ChangeLog --- a/ChangeLog Fri Jan 23 17:17:51 2004 +0000 +++ b/ChangeLog Sat Jan 24 11:45:11 2004 +0000 @@ -1,3 +1,23 @@ +2003-1-23 Brian Masney + * src/text/gftp-text.c src/uicommon/gftpui.c - added file transfer + functions to the command line. + + * src/uicommon/gftpui_transfer.c src/uicommon/gftpui.h src/text/textui.c + src/gtk/gtkui_transfer.c - added + gftpui_{start,update,finish}_current_file_in_transfer() functions + that will be called throughout the lifetime of a file transfer. + Also, gftpui_start_transfer() that will be called whenever a file + transfer is created + + * src/uicommon/gftpui.h src/uicommon/gftpui.c src/gtk/gftp-gtk.c + src/gtk/transfer.c - added other_uidata and other_request arguments + to all of the command line functions + + * lib/protocols.c lib/gftp.h - set the filespec argument to + gftp_get_next_file to be a constant + + * lib/gftp.h - added tot_file_trans variable to gftp_transfer struct + 2003-1-21 Brian Masney * lib/config_file.c lib/gftp.h - set the character string arguments to const for the following functions: gftp_lookup_global_option(), @@ -2057,7 +2077,7 @@ * cvsclean - added this script - * *.[ch] - added $Id: ChangeLog,v 1.207 2004/01/21 23:35:30 masneyb Exp $ tags + * *.[ch] - added $Id: ChangeLog,v 1.208 2004/01/24 11:45:06 masneyb Exp $ tags * debian/* - updated files from Debian maintainer diff -r 6b25e7a2ff20 -r 14da115b149b lib/gftp.h --- a/lib/gftp.h Fri Jan 23 17:17:51 2004 +0000 +++ b/lib/gftp.h Sat Jan 24 11:45:11 2004 +0000 @@ -482,6 +482,8 @@ current_file_retries; off_t curtrans, /* Current transfered bytes for this file */ + tot_file_trans, /* Total number of bytes in the file being + transferred */ curresumed, /* Resumed bytes for this file */ trans_bytes, /* Amount of data transfered for entire transfer */ @@ -842,7 +844,7 @@ const char *url ); int gftp_get_next_file ( gftp_request * request, - char *filespec, + const char *filespec, gftp_file *fle ); int gftp_end_transfer ( gftp_request * request ); diff -r 6b25e7a2ff20 -r 14da115b149b lib/protocols.c --- a/lib/protocols.c Fri Jan 23 17:17:51 2004 +0000 +++ b/lib/protocols.c Sat Jan 24 11:45:11 2004 +0000 @@ -512,7 +512,8 @@ int -gftp_get_next_file (gftp_request * request, char *filespec, gftp_file * fle) +gftp_get_next_file (gftp_request * request, const char *filespec, + gftp_file * fle) { int fd, ret; diff -r 6b25e7a2ff20 -r 14da115b149b src/gtk/gftp-gtk.c --- a/src/gtk/gftp-gtk.c Fri Jan 23 17:17:51 2004 +0000 +++ b/src/gtk/gftp-gtk.c Sat Jan 24 11:45:11 2004 +0000 @@ -166,7 +166,7 @@ str = gtk_entry_get_text (GTK_ENTRY (ddata->edit)); if (str != NULL && *str != '\0') - gftpui_common_cmd_open (wdata, wdata->request, str); + gftpui_common_cmd_open (wdata, wdata->request, NULL, NULL, str); } diff -r 6b25e7a2ff20 -r 14da115b149b src/gtk/gtkui_transfer.c --- a/src/gtk/gtkui_transfer.c Fri Jan 23 17:17:51 2004 +0000 +++ b/src/gtk/gtkui_transfer.c Sat Jan 24 11:45:11 2004 +0000 @@ -22,6 +22,31 @@ void +gftpui_start_current_file_in_transfer (gftp_transfer * tdata) +{ +} + + +void +gftpui_update_current_file_in_transfer (gftp_transfer * tdata) +{ +} + + +void +gftpui_finish_current_file_in_transfer (gftp_transfer * tdata) +{ +} + + +void +gftpui_start_transfer (gftp_transfer * tdata) +{ + /* Not used in GTK+ port. This is polled instead */ +} + + +void gftpui_add_file_to_transfer (gftp_transfer * tdata, GList * curfle, char *filepos) { diff -r 6b25e7a2ff20 -r 14da115b149b src/gtk/transfer.c --- a/src/gtk/transfer.c Fri Jan 23 17:17:51 2004 +0000 +++ b/src/gtk/transfer.c Sat Jan 24 11:45:11 2004 +0000 @@ -61,7 +61,7 @@ if (wdata->request == request) gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Connecting...")); - return (gftpui_common_cmd_open (wdata, request, NULL)); + return (gftpui_common_cmd_open (wdata, request, NULL, NULL, NULL)); } @@ -743,6 +743,7 @@ gtk_ctree_node_set_text (GTK_CTREE (dlwdw), tempfle->user_data, 1, dlstr); } + static void update_window_transfer_bytes (gftp_window_data * wdata) { diff -r 6b25e7a2ff20 -r 14da115b149b src/text/gftp-text.c --- a/src/text/gftp-text.c Fri Jan 23 17:17:51 2004 +0000 +++ b/src/text/gftp-text.c Sat Jan 24 11:45:11 2004 +0000 @@ -259,309 +259,3 @@ return (0); } -#if 0 -int -gftp_text_open (gftp_request * request, char *command, gpointer *data) -{ - char tempstr[255], *pos; - - if (GFTP_IS_CONNECTED (request)) - { - gftp_disconnect (request); - } - - if (*command == '\0') - { - gftp_text_log (gftp_logging_error, request, - _("usage: open [[ftp://][user:pass@]ftp-site[:port][/directory]]\n")); - return (1); - } - - if (gftp_parse_url (request, command) < 0) - return (1); - - if (request->need_userpass) - { - if (request->username == NULL || *request->username == '\0') - { - if ((pos = gftp_text_ask_question ("Username [anonymous]", 1, tempstr, - sizeof (tempstr))) != NULL) - { - gftp_set_username (request, pos); - gftp_set_password (request, NULL); - } - } - - if (request->username != NULL && - strcmp (request->username, "anonymous") != 0 && - (request->password == NULL || *request->password == '\0')) - { - if ((pos = gftp_text_ask_question ("Password", 0, tempstr, - sizeof (tempstr))) == NULL) - return (1); - gftp_set_password (request, pos); - } - } - - gftp_connect (request); - return (1); -} - - -int -gftp_text_mget_file (gftp_request * request, char *command, gpointer *data) -{ - gftp_transfer * transfer; - gftp_file * fle; - - if (!GFTP_IS_CONNECTED (gftp_text_remreq)) - { - gftp_text_log (gftp_logging_error, request, - _("Error: Not connected to a remote site\n")); - return (1); - } - - if (*command == '\0') - { - gftp_text_log (gftp_logging_error, request, - _("usage: mget \n")); - return (1); - } - - transfer = gftp_tdata_new (); - transfer->fromreq = gftp_text_remreq; - transfer->toreq = gftp_text_locreq; - - /* FIXME - ask whether to resume/skip/overwrite */ - if (gftp_list_files (transfer->fromreq) != 0) - { - transfer->fromreq = transfer->toreq = NULL; - free_tdata (transfer); - return (1); - } - fle = g_malloc0 (sizeof (*fle)); - while (gftp_get_next_file (transfer->fromreq, command, fle) > 0) - { - if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0) - { - gftp_file_destroy (fle); - continue; - } - transfer->files = g_list_append (transfer->files, fle); - fle = g_malloc (sizeof (*fle)); - } - g_free (fle); - gftp_end_transfer (transfer->fromreq); - - if (transfer->files == NULL) - { - transfer->fromreq = transfer->toreq = NULL; - free_tdata (transfer); - return (1); - } - - if (gftp_get_all_subdirs (transfer, NULL) != 0) - { - transfer->fromreq = transfer->toreq = NULL; - free_tdata (transfer); - return (1); - } - - if (transfer->files == NULL) - { - transfer->fromreq = transfer->toreq = NULL; - free_tdata (transfer); - return (1); - } - - gftp_text_transfer_files (transfer); - transfer->fromreq = transfer->toreq = NULL; - free_tdata (transfer); - return (1); -} - - -int -gftp_text_mput_file (gftp_request * request, char *command, gpointer *data) -{ - gftp_transfer * transfer; - gftp_file * fle; - - if (!GFTP_IS_CONNECTED (gftp_text_remreq)) - { - gftp_text_log (gftp_logging_error, request, - _("Error: Not connected to a remote site\n")); - return (1); - } - - if (*command == '\0') - { - gftp_text_log (gftp_logging_error, request, - _("usage: mput \n")); - return (1); - } - - transfer = gftp_tdata_new (); - transfer->fromreq = gftp_text_locreq; - transfer->toreq = gftp_text_remreq; - - if (gftp_list_files (transfer->fromreq) != 0) - { - transfer->fromreq = transfer->toreq = NULL; - free_tdata (transfer); - return (1); - } - fle = g_malloc (sizeof (*fle)); - while (gftp_get_next_file (transfer->fromreq, command, fle) > 0) - { - if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0) - { - gftp_file_destroy (fle); - continue; - } - transfer->files = g_list_append (transfer->files, fle); - fle = g_malloc (sizeof (*fle)); - } - g_free (fle); - gftp_end_transfer (transfer->fromreq); - - if (transfer->files == NULL) - { - transfer->fromreq = transfer->toreq = NULL; - free_tdata (transfer); - return (1); - } - - if (gftp_get_all_subdirs (transfer, NULL) != 0) - { - transfer->fromreq = transfer->toreq = NULL; - free_tdata (transfer); - return (1); - } - - if (transfer->files == NULL) - { - transfer->fromreq = transfer->toreq = NULL; - free_tdata (transfer); - return (1); - } - - gftp_text_transfer_files (transfer); - transfer->fromreq = transfer->toreq = NULL; - free_tdata (transfer); - return (1); -} - - -int -gftp_text_transfer_files (gftp_transfer * transfer) -{ - int i, j, sw, tot; - intptr_t preserve_permissions; - char buf[8192], *progress = "|/-\\"; - struct timeval updatetime; - long fromsize, total; - gftp_file * curfle; - ssize_t num_read; - mode_t mode; - - gftp_lookup_request_option (transfer->fromreq, "preserve_permissions", - &preserve_permissions); - - for (transfer->curfle = transfer->files; - transfer->curfle != NULL; - transfer->curfle = transfer->curfle->next) - { - curfle = transfer->curfle->data; - if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP) - continue; - - if (curfle->isdir && transfer->toreq->mkdir != NULL) - { - transfer->toreq->mkdir (transfer->toreq, curfle->destfile); - continue; - } - - transfer->curtrans = curfle->startsize; - fromsize = gftp_transfer_file (transfer->fromreq, curfle->file, -1, - curfle->startsize, transfer->toreq, curfle->destfile, - -1, curfle->startsize); - if (fromsize < 0) - return (1); - - gettimeofday (&transfer->starttime, NULL); - memcpy (&transfer->lasttime, &transfer->starttime, - sizeof (transfer->lasttime)); - memset (&updatetime, 0, sizeof (updatetime)); - - total = 0; - i = 0; - num_read = -1; - while (!cancel && (num_read = gftp_get_next_file_chunk (transfer->fromreq, - buf, sizeof (buf))) > 0) - { - printf ("\r%c ", progress[i++]); - fflush (stdout); - if (progress[i] == '\0') - i = 0; - - total += num_read; - gftp_calc_kbs (transfer, num_read); - if (transfer->lasttime.tv_sec - updatetime.tv_sec >= 1 || total >= fromsize) - { - sw = gftp_text_get_win_size () - 20; - tot = (float) total / (float) fromsize * (float) sw; - - if (tot > sw) - tot = sw; - printf ("["); - for (j=0; jkbs); - fflush (stdout); - memcpy (&updatetime, &transfer->lasttime, sizeof (updatetime)); - } - - if (gftp_put_next_file_chunk (transfer->toreq, buf, num_read) < 0) - { - num_read = -1; - break; - } - } - printf ("\n"); - - if (num_read < 0) - { - gftp_text_log (gftp_logging_misc, transfer->fromreq, - _("Could not download %s\n"), curfle->file); - gftp_disconnect (transfer->fromreq); - gftp_disconnect (transfer->toreq); - } - else - { - gftp_text_log (gftp_logging_misc, transfer->fromreq, - _("Successfully transferred %s\n"), curfle->file); - gftp_end_transfer (transfer->fromreq); - gftp_end_transfer (transfer->toreq); - } - - if (!curfle->is_fd && preserve_permissions) - { - if (curfle->attribs) - { - mode = gftp_parse_attribs (curfle->attribs); - if (mode != 0) - gftp_chmod (transfer->toreq, curfle->destfile, mode); - } - - if (curfle->datetime != 0) - gftp_set_file_time (transfer->toreq, curfle->destfile, - curfle->datetime); - } - } - return (1); -} - -#endif diff -r 6b25e7a2ff20 -r 14da115b149b src/text/gftp-text.h --- a/src/text/gftp-text.h Fri Jan 23 17:17:51 2004 +0000 +++ b/src/text/gftp-text.h Sat Jan 24 11:45:11 2004 +0000 @@ -30,6 +30,8 @@ #include #endif +int gftp_text_get_win_size ( void ); + char * gftp_text_ask_question ( const char *question, int echo, char *buf, diff -r 6b25e7a2ff20 -r 14da115b149b src/text/textui.c --- a/src/text/textui.c Fri Jan 23 17:17:51 2004 +0000 +++ b/src/text/textui.c Sat Jan 24 11:45:11 2004 +0000 @@ -83,7 +83,7 @@ void gftpui_add_file_to_transfer (gftp_transfer * tdata, GList * curfle, - char *filepos ) + char *filepos ) { /* FIXME */ } @@ -95,3 +95,62 @@ /* FIXME */ } + +static void +_gftpui_text_print_status (gftp_transfer * tdata) +{ + static int progress_pos = 0; + char *progress = "|/-\\"; + int sw, tot, i; + + printf ("\r%c [", progress[progress_pos++]); + + if (progress[progress_pos] == '\0') + progress_pos = 0; + + sw = gftp_text_get_win_size () - 20; + tot = (float) tdata->curtrans / (float) tdata->tot_file_trans * (float) sw; + + if (tot > sw) + tot = sw; + + for (i=0; ikbs); + + fflush (stdout); +} + + +void +gftpui_start_current_file_in_transfer (gftp_transfer * tdata) +{ + _gftpui_text_print_status (tdata); +} + + +void +gftpui_update_current_file_in_transfer (gftp_transfer * tdata) +{ + _gftpui_text_print_status (tdata); +} + + +void +gftpui_finish_current_file_in_transfer (gftp_transfer * tdata) +{ + _gftpui_text_print_status (tdata); + printf ("\n"); +} + + +void +gftpui_start_transfer (gftp_transfer * tdata) +{ + gftpui_common_transfer_files (tdata); +} + diff -r 6b25e7a2ff20 -r 14da115b149b src/uicommon/gftpui.c --- a/src/uicommon/gftpui.c Fri Jan 23 17:17:51 2004 +0000 +++ b/src/uicommon/gftpui.c Sat Jan 24 11:45:11 2004 +0000 @@ -154,6 +154,7 @@ static int gftpui_common_cmd_about (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftpui_common_about (gftpui_common_logfunc, NULL); @@ -163,6 +164,7 @@ static int gftpui_common_cmd_ascii (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(1)); @@ -172,6 +174,7 @@ static int gftpui_common_cmd_binary (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftp_set_global_option ("ascii_transfers", GINT_TO_POINTER(0)); @@ -181,6 +184,7 @@ static int gftpui_common_cmd_chmod (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftpui_callback_data * cdata; @@ -222,7 +226,8 @@ static int gftpui_common_cmd_rename (void *uidata, gftp_request * request, - const char *command) + void *other_uidata, gftp_request * other_request, + const char *command) { gftpui_callback_data * cdata; char *pos; @@ -262,7 +267,8 @@ static int gftpui_common_cmd_delete (void *uidata, gftp_request * request, - const char *command) + void *other_uidata, gftp_request * other_request, + const char *command) { gftpui_callback_data * cdata; @@ -296,6 +302,7 @@ static int gftpui_common_cmd_rmdir (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftpui_callback_data * cdata; @@ -330,6 +337,7 @@ static int gftpui_common_cmd_site (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftpui_callback_data * cdata; @@ -364,6 +372,7 @@ static int gftpui_common_cmd_mkdir (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftpui_callback_data * cdata; @@ -398,6 +407,7 @@ static int gftpui_common_cmd_chdir (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftpui_callback_data * cdata; @@ -453,6 +463,7 @@ static int gftpui_common_cmd_close (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftp_disconnect (request); @@ -462,6 +473,7 @@ static int gftpui_common_cmd_pwd (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { if (!GFTP_IS_CONNECTED (request)) @@ -480,6 +492,7 @@ static int gftpui_common_cmd_quit (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftp_shutdown(); @@ -490,6 +503,7 @@ static int gftpui_common_cmd_clear (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { if (strcasecmp (command, "cache") == 0) @@ -535,6 +549,7 @@ static int gftpui_common_cmd_ls (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { char *startcolor, *endcolor, *tempstr; @@ -584,6 +599,7 @@ int gftpui_common_cmd_open (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftpui_callback_data * cdata; @@ -650,6 +666,7 @@ static int gftpui_common_cmd_set (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { gftp_config_vars * cv, newcv; @@ -730,6 +747,7 @@ static int gftpui_common_cmd_help (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, const char *command) { int i, j, ele, numrows, numcols = 6, handled, number_commands, cmdlen, @@ -796,6 +814,109 @@ } +static void +_gftpui_common_transfer_files (void *fromuidata, gftp_request * fromrequest, + void *touidata, gftp_request * torequest, + const char *cmd, const char *filespec) +{ + gftp_transfer * tdata; + gftp_file * fle; + + if (!GFTP_IS_CONNECTED (fromrequest) || + !GFTP_IS_CONNECTED (torequest)) + { + fromrequest->logging_function (gftp_logging_error, fromrequest, + _("Error: Not connected to a remote site\n")); + return; + } + + if (*filespec == '\0') + { + fromrequest->logging_function (gftp_logging_error, fromrequest, + _("usage: %s \n"), cmd); + return; + } + + tdata = gftp_tdata_new (); + tdata->fromreq = fromrequest; + tdata->toreq = torequest; + + if (gftp_list_files (tdata->fromreq) != 0) + { + tdata->fromreq = tdata->toreq = NULL; + free_tdata (tdata); + return; + } + + fle = g_malloc0 (sizeof (*fle)); + while (gftp_get_next_file (tdata->fromreq, filespec, fle) > 0) + { + if (strcmp (fle->file, ".") == 0 || strcmp (fle->file, "..") == 0) + { + gftp_file_destroy (fle); + continue; + } + + tdata->files = g_list_append (tdata->files, fle); + fle = g_malloc (sizeof (*fle)); + } + + g_free (fle); + + gftp_end_transfer (tdata->fromreq); + + if (tdata->files == NULL) + { + tdata->fromreq = tdata->toreq = NULL; + free_tdata (tdata); + return; + } + + if (gftp_get_all_subdirs (tdata, NULL) != 0) + { + tdata->fromreq = tdata->toreq = NULL; + free_tdata (tdata); + return; + } + + if (tdata->files == NULL) + { + tdata->fromreq = tdata->toreq = NULL; + free_tdata (tdata); + return; + } + + gftpui_common_add_file_transfer (tdata->fromreq, tdata->toreq, + fromuidata, touidata, tdata->files); + + g_free (tdata); + + return; +} + + +int +gftpui_common_cmd_mget_file (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, + const char *command) +{ + _gftpui_common_transfer_files (uidata, request, other_uidata, other_request, + "mget", command); + return (1); +} + + +int +gftpui_common_cmd_mput_file (void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, + const char *command) +{ + _gftpui_common_transfer_files (other_uidata, other_request, uidata, request, + "mput", command); + return (1); +} + + gftpui_common_methods gftpui_common_commands[] = { {N_("about"), 2, gftpui_common_cmd_about, gftpui_common_request_none, N_("Shows gFTP information"), NULL}, @@ -815,10 +936,8 @@ N_("Disconnects from the remote site"), NULL}, {N_("delete"), 1, gftpui_common_cmd_delete, gftpui_common_request_remote, N_("Removes a remote file"), NULL}, -/* FIXME - {N_("get"), 1, gftp_text_mget_file, gftpui_common_request_none, + {N_("get"), 1, gftpui_common_cmd_mget_file, gftpui_common_request_remote, N_("Downloads remote file(s)"), NULL}, -*/ {N_("help"), 1, gftpui_common_cmd_help, gftpui_common_request_none, N_("Shows this help screen"), NULL}, {N_("lcd"), 3, gftpui_common_cmd_chdir, gftpui_common_request_local, @@ -841,22 +960,16 @@ N_("Remove a local directory"), NULL}, {N_("ls"), 2, gftpui_common_cmd_ls, gftpui_common_request_remote, N_("Shows the directory listing for the current remote directory"), NULL}, -/* FIXME - {N_("mget"), 2, gftp_text_mget_file, gftpui_common_request_none, + {N_("mget"), 2, gftpui_common_cmd_mget_file, gftpui_common_request_remote, N_("Downloads remote file(s)"), NULL}, -*/ - {N_("mkdir"), 2, gftpui_common_cmd_mkdir, gftpui_common_request_remote, + {N_("mkdir"), 2, gftpui_common_cmd_mkdir, gftpui_common_request_remote, N_("Creates a remote directory"), NULL}, -/* FIXME - {N_("mput"), 2, gftp_text_mput_file, gftpui_common_request_none, + {N_("mput"), 2, gftpui_common_cmd_mput_file, gftpui_common_request_remote, N_("Uploads local file(s)"), NULL}, -*/ {N_("open"), 1, gftpui_common_cmd_open, gftpui_common_request_remote, N_("Opens a connection to a remote site"), NULL}, -/* FIXME - {N_("put"), 2, gftp_text_mput_file, gftpui_common_request_none, + {N_("put"), 2, gftpui_common_cmd_mput_file, gftpui_common_request_remote, N_("Uploads local file(s)"), NULL}, -*/ {N_("pwd"), 2, gftpui_common_cmd_pwd, gftpui_common_request_remote, N_("Show current remote directory"), NULL}, {N_("quit"), 1, gftpui_common_cmd_quit, gftpui_common_request_none, @@ -866,7 +979,8 @@ {N_("rmdir"), 2, gftpui_common_cmd_rmdir, gftpui_common_request_remote, N_("Remove a remote directory"), NULL}, {N_("set"), 1, gftpui_common_cmd_set, gftpui_common_request_none, - N_("Show configuration file variables. You can also set variables by set var=val"), gftpui_common_set_show_subhelp}, + N_("Show configuration file variables. You can also set variables by set var=val"), + gftpui_common_set_show_subhelp}, {N_("site"), 2, gftpui_common_cmd_site, gftpui_common_request_remote, N_("Run a site specific command"), NULL}, {NULL, 0, NULL, gftpui_common_request_none, @@ -878,11 +992,11 @@ void *remui, gftp_request * remreq, const char *command) { - gftp_request * request; - const char *stpos; + gftp_request * request, * other_request; + void *uidata, *other_uidata; char *pos, *newstr; + const char *stpos; size_t cmdlen; - void *uidata; int ret, i; size_t len; @@ -929,21 +1043,28 @@ { request = locreq; uidata = locui; + + other_request = remreq; + other_uidata = remui; } else if (gftpui_common_commands[i].reqtype == gftpui_common_request_remote) { request = remreq; uidata = remui; + + other_request = locreq; + other_uidata = locui; } else { - request = NULL; - uidata = NULL; + request = other_request = NULL; + uidata = other_uidata = NULL; } if (gftpui_common_commands[i].command != NULL) { - ret = gftpui_common_commands[i].func (uidata, request, pos); + ret = gftpui_common_commands[i].func (uidata, request, + other_uidata, other_request, pos); } else { @@ -1078,6 +1199,7 @@ gftpui_ask_transfer (tdata); } + gftpui_start_transfer (tdata); return (tdata); } @@ -1115,20 +1237,16 @@ int gftpui_common_transfer_files (gftp_transfer * tdata) { + intptr_t preserve_permissions; int i, mode, tofd, fromfd; - intptr_t preserve_permissions; + struct timeval updatetime; + ssize_t num_read, ret; + gftp_file * curfle; char buf[8192]; - off_t fromsize, total; - gftp_file * curfle; - ssize_t num_read, ret; tdata->curfle = tdata->files; gettimeofday (&tdata->starttime, NULL); - memcpy (&tdata->lasttime, &tdata->starttime, - sizeof (tdata->lasttime)); - - gftp_lookup_request_option (tdata->fromreq, "preserve_permissions", - &preserve_permissions); + memcpy (&tdata->lasttime, &tdata->starttime, sizeof (tdata->lasttime)); while (tdata->curfle != NULL) { @@ -1153,10 +1271,11 @@ if (g_thread_supported ()) g_static_mutex_unlock (&tdata->structmutex); + continue; } - fromsize = -1; + tdata->tot_file_trans = -1; if (gftp_connect (tdata->fromreq) == 0 && gftp_connect (tdata->toreq) == 0) { @@ -1191,8 +1310,8 @@ if (GFTP_IS_CONNECTED (tdata->fromreq) && GFTP_IS_CONNECTED (tdata->toreq)) { - fromsize = gftp_transfer_file (tdata->fromreq, curfle->file, - fromfd, + tdata->tot_file_trans = gftp_transfer_file (tdata->fromreq, + curfle->file, fromfd, curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0, tdata->toreq, curfle->destfile, tofd, @@ -1206,9 +1325,9 @@ { tdata->fromreq->logging_function (gftp_logging_misc, tdata->fromreq, - _("Error: Remote site disconnected after trying to tdata file\n")); + _("Error: Remote site disconnected after trying to transfer file\n")); } - else if (fromsize < 0) + else if (tdata->tot_file_trans < 0) { if (g_thread_supported ()) g_static_mutex_lock (&tdata->structmutex); @@ -1233,14 +1352,21 @@ if (g_thread_supported ()) g_static_mutex_unlock (&tdata->structmutex); - total = 0; + memset (&updatetime, 0, sizeof (updatetime)); + gftpui_start_current_file_in_transfer (tdata); + i = 0; while (!tdata->cancel && (num_read = gftp_get_next_file_chunk (tdata->fromreq, buf, sizeof (buf))) > 0) { - total += num_read; gftp_calc_kbs (tdata, num_read); + if (tdata->lasttime.tv_sec - updatetime.tv_sec >= 1 || + tdata->curtrans >= tdata->tot_file_trans) + { + gftpui_update_current_file_in_transfer (tdata); + memcpy (&updatetime, &tdata->lasttime, sizeof (updatetime)); + } if ((ret = gftp_put_next_file_chunk (tdata->toreq, buf, num_read)) < 0) @@ -1249,6 +1375,8 @@ break; } } + + gftpui_finish_current_file_in_transfer (tdata); } if (tdata->cancel) @@ -1286,10 +1414,13 @@ tdata->fromreq->logging_function (gftp_logging_misc, tdata->fromreq, - _("Successfully tdatared %s at %.2f KB/s\n"), + _("Successfully transferred %s at %.2f KB/s\n"), curfle->file, tdata->kbs); } + gftp_lookup_request_option (tdata->fromreq, "preserve_permissions", + &preserve_permissions); + if (!curfle->is_fd && preserve_permissions) { if (curfle->attribs) diff -r 6b25e7a2ff20 -r 14da115b149b src/uicommon/gftpui.h --- a/src/uicommon/gftpui.h Fri Jan 23 17:17:51 2004 +0000 +++ b/src/uicommon/gftpui.h Sat Jan 24 11:45:11 2004 +0000 @@ -50,7 +50,9 @@ { char *command; int minlen; - int (*func)(void *uidata, gftp_request * request, const char *command); + int (*func)(void *uidata, gftp_request * request, + void *other_uidata, gftp_request * other_request, + const char *command); gftpui_common_request_type reqtype; char *cmd_description; int (*subhelp_func) (const char *topic); @@ -102,6 +104,8 @@ int gftpui_common_cmd_open ( void *uidata, gftp_request * request, + void *other_uidata, + gftp_request * other_request, const char *command ); gftp_transfer * gftpui_common_add_file_transfer ( gftp_request * fromreq, @@ -155,4 +159,12 @@ void gftpui_ask_transfer ( gftp_transfer * tdata ); +void gftpui_start_current_file_in_transfer ( gftp_transfer * tdata ); + +void gftpui_update_current_file_in_transfer ( gftp_transfer * tdata ); + +void gftpui_finish_current_file_in_transfer ( gftp_transfer * tdata ); + +void gftpui_start_transfer ( gftp_transfer * tdata ); + #endif