📄 transfer.c
字号:
/*****************************************************************************//* transfer.c - functions to handle transfering files *//* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> *//* *//* This program is free software; you can redistribute it and/or modify *//* it under the terms of the GNU General Public License as published by *//* the Free Software Foundation; either version 2 of the License, or *//* (at your option) any later version. *//* *//* This program is distributed in the hope that it will be useful, *//* but WITHOUT ANY WARRANTY; without even the implied warranty of *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *//* GNU General Public License for more details. *//* *//* You should have received a copy of the GNU General Public License *//* along with this program; if not, write to the Free Software *//* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//*****************************************************************************/#include "gftp-gtk.h"static const char cvsid[] = "$Id: transfer.c,v 1.76 2005/01/25 02:34:19 masneyb Exp $";static int num_transfers_in_progress = 0;intftp_list_files (gftp_window_data * wdata){ gftpui_callback_data * cdata; gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Receiving file names...")); cdata = g_malloc0 (sizeof (*cdata)); cdata->request = wdata->request; cdata->uidata = wdata; cdata->run_function = gftpui_common_run_ls; cdata->dont_refresh = 1; gftpui_common_run_callback_function (cdata); wdata->files = cdata->files; g_free (cdata); if (wdata->files == NULL || !GFTP_IS_CONNECTED (wdata->request)) { gftpui_disconnect (wdata); return (0); } wdata->sorted = 0; sortrows (GTK_CLIST (wdata->listbox), -1, (gpointer) wdata); if (IS_NONE_SELECTED (wdata)) gtk_clist_select_row (GTK_CLIST (wdata->listbox), 0, 0); return (1);}intftp_connect (gftp_window_data * wdata, gftp_request * request, int getdir){ if (wdata->request == request) gtk_label_set (GTK_LABEL (wdata->hoststxt), _("Connecting...")); return (gftpui_common_cmd_open (wdata, request, NULL, NULL, NULL));}void get_files (gpointer data){ transfer_window_files (&window2, &window1);}voidput_files (gpointer data){ transfer_window_files (&window1, &window2);}voidtransfer_window_files (gftp_window_data * fromwdata, gftp_window_data * towdata){ gftp_file * tempfle, * newfle; GList * templist, * filelist; gftp_transfer * transfer; int num, ret, disconnect; if (!check_status (_("Transfer Files"), fromwdata, 1, 0, 1, towdata->request->put_file != NULL && fromwdata->request->get_file != NULL)) return; if (!GFTP_IS_CONNECTED (fromwdata->request) || !GFTP_IS_CONNECTED (towdata->request)) { ftp_log (gftp_logging_error, NULL, _("Retrieve Files: Not connected to a remote site\n")); return; } if (check_reconnect (fromwdata) < 0 || check_reconnect (towdata) < 0) return; transfer = g_malloc0 (sizeof (*transfer)); transfer->fromreq = gftp_copy_request (fromwdata->request); transfer->toreq = gftp_copy_request (towdata->request); transfer->fromwdata = fromwdata; transfer->towdata = towdata; num = 0; templist = gftp_gtk_get_list_selection (fromwdata); filelist = fromwdata->files; while (templist != NULL) { templist = get_next_selection (templist, &filelist, &num); tempfle = filelist->data; if (strcmp (tempfle->file, "..") != 0) { newfle = copy_fdata (tempfle); transfer->files = g_list_append (transfer->files, newfle); } } if (transfer->files != NULL) { gftp_swap_socks (transfer->fromreq, fromwdata->request); gftp_swap_socks (transfer->toreq, towdata->request); ret = gftp_gtk_get_subdirs (transfer, &fromwdata->tid); if (ret < 0) disconnect = 1; else disconnect = 0; if (!GFTP_IS_CONNECTED (transfer->fromreq)) { gftpui_disconnect (fromwdata); disconnect = 1; } if (!GFTP_IS_CONNECTED (transfer->toreq)) { gftpui_disconnect (towdata); disconnect = 1; } if (disconnect) { free_tdata (transfer); return; } gftp_swap_socks (fromwdata->request, transfer->fromreq); gftp_swap_socks (towdata->request, transfer->toreq); } if (transfer->files != NULL) { gftpui_common_add_file_transfer (transfer->fromreq, transfer->toreq, transfer->fromwdata, transfer->towdata, transfer->files); g_free (transfer); } else free_tdata (transfer);}static intgftpui_gtk_tdata_connect (gftpui_callback_data * cdata){ gftp_transfer * tdata; int ret; tdata = cdata->user_data; if (tdata->fromreq != NULL) { ret = gftp_connect (tdata->fromreq); if (ret < 0) return (ret); } if (tdata->toreq != NULL) { ret = gftp_connect (tdata->toreq); if (ret < 0) return (ret); } return (0);}static voidgftpui_gtk_tdata_disconnect (gftpui_callback_data * cdata){ gftp_transfer * tdata; tdata = cdata->user_data; if (tdata->fromreq != NULL) gftp_disconnect (tdata->fromreq); if (tdata->toreq != NULL) gftp_disconnect (tdata->toreq); cdata->request->datafd = -1;}static int_gftp_getdir_thread (gftpui_callback_data * cdata){ return (gftp_get_all_subdirs (cdata->user_data, NULL));}intgftp_gtk_get_subdirs (gftp_transfer * transfer, pthread_t *tid){ gftpui_callback_data * cdata; long numfiles, numdirs; guint timeout_num; int ret; cdata = g_malloc0 (sizeof (*cdata)); cdata->user_data = transfer; cdata->uidata = transfer->fromwdata; cdata->request = ((gftp_window_data *) transfer->fromwdata)->request; cdata->run_function = _gftp_getdir_thread; cdata->connect_function = gftpui_gtk_tdata_connect; cdata->disconnect_function = gftpui_gtk_tdata_disconnect; cdata->dont_check_connection = 1; cdata->dont_refresh = 1; timeout_num = gtk_timeout_add (100, progress_timeout, transfer); ret = gftpui_common_run_callback_function (cdata); gtk_timeout_remove (timeout_num); numfiles = transfer->numfiles; numdirs = transfer->numdirs; transfer->numfiles = transfer->numdirs = -1; update_directory_download_progress (transfer); transfer->numfiles = numfiles; transfer->numdirs = numdirs; g_free (cdata); return (ret);}static voidremove_file (char *filename){ if (unlink (filename) == 0) ftp_log (gftp_logging_misc, NULL, _("Successfully removed %s\n"), filename); else ftp_log (gftp_logging_error, NULL, _("Error: Could not remove file %s: %s\n"), filename, g_strerror (errno));}static voidfree_edit_data (gftp_viewedit_data * ve_proc){ int i; if (ve_proc->torequest) gftp_request_destroy (ve_proc->torequest, 1); if (ve_proc->filename) g_free (ve_proc->filename); if (ve_proc->remote_filename) g_free (ve_proc->remote_filename); for (i = 0; ve_proc->argv[i] != NULL; i++) g_free (ve_proc->argv[i]); g_free (ve_proc->argv); g_free (ve_proc);}static voiddont_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata){ remove_file (ve_proc->filename); free_edit_data (ve_proc);}static voiddo_upload (gftp_viewedit_data * ve_proc, gftp_dialog_data * ddata){ gftp_transfer * tdata; gftp_file * tempfle; GList * newfile; tempfle = g_malloc0 (sizeof (*tempfle)); tempfle->destfile = gftp_build_path (ve_proc->torequest, ve_proc->torequest->directory, ve_proc->remote_filename, NULL); ve_proc->remote_filename = NULL; tempfle->file = ve_proc->filename; ve_proc->filename = NULL; tempfle->done_rm = 1; newfile = g_list_append (NULL, tempfle); tdata = gftpui_common_add_file_transfer (ve_proc->fromwdata->request, ve_proc->torequest, ve_proc->fromwdata, ve_proc->towdata, newfile); free_edit_data (ve_proc); if (tdata != NULL) tdata->conn_error_no_timeout = 1;}static voidcheck_done_process (void){ gftp_viewedit_data * ve_proc; GList * curdata, *deldata; int ret, procret; struct stat st; char *str; pid_t pid; gftpui_common_child_process_done = 0; while ((pid = waitpid (-1, &ret, WNOHANG)) > 0) { curdata = viewedit_processes; while (curdata != NULL) { ve_proc = curdata->data; deldata = curdata; curdata = curdata->next; if (ve_proc->pid == pid) { viewedit_processes = g_list_remove_link (viewedit_processes, deldata); if (WIFEXITED (ret)) { procret = WEXITSTATUS (ret); if (procret != 0) { ftp_log (gftp_logging_error, NULL, _("Error: Child %d returned %d\n"), pid, procret); remove_file (ve_proc->filename); continue; } else ftp_log (gftp_logging_misc, NULL, _("Child %d returned successfully\n"), pid); } else ftp_log (gftp_logging_error, NULL, _("Error: Child %d did not terminate properly\n"), pid); if (!ve_proc->view && !ve_proc->dontupload) { /* We was editing the file. Upload it */ ret = stat (ve_proc->filename, &st); if (ret == -1) ftp_log (gftp_logging_error, NULL, _("Error: Cannot get information about file %s: %s\n"), ve_proc->filename, g_strerror (errno)); else if (st.st_mtime == ve_proc->st.st_mtime) { ftp_log (gftp_logging_misc, NULL, _("File %s was not changed\n"), ve_proc->filename); remove_file (ve_proc->filename); } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -