static void do_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 void _gftpui_common_cmd_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 <filespec>\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, 0); continue; } tdata->files = g_list_append (tdata->files, fle); fle = g_malloc0 (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; }
void transfer_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); 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 void do_view_or_edit_file (gftp_window_data * fromwdata, int is_view) { GList * templist, * filelist, * newfile; gftp_window_data * towdata; gftp_file * new_fle; char *suffix; int num; if (!check_status (is_view ? _("View") : _("Edit"), fromwdata, 0, 1, 1, 1)) return; towdata = fromwdata == &window1 ? &window2 : &window1; templist = GTK_CLIST (fromwdata->listbox)->selection; num = 0; filelist = fromwdata->files; templist = get_next_selection (templist, &filelist, &num); curfle = filelist->data; if (S_ISDIR (curfle->st_mode)) { if (is_view) ftp_log (gftp_logging_error, NULL, _("View: %s is a directory. Cannot view it.\n"), curfle->file); else ftp_log (gftp_logging_error, NULL, _("Edit: %s is a directory. Cannot edit it.\n"), curfle->file); return; } if (strcmp (gftp_protocols[fromwdata->request->protonum].name, "Local") == 0) view_file (curfle->file, 0, is_view, 0, 1, 1, NULL, fromwdata); else { new_fle = copy_fdata (curfle); if (new_fle->destfile) g_free (new_fle->destfile); if ((suffix = strrchr (curfle->file, '.')) != NULL) { new_fle->destfile = g_strconcat (g_get_tmp_dir (), "/gftp-view.XXXXXX", suffix, NULL); new_fle->fd = mkstemps (new_fle->destfile, strlen (suffix)); } else { new_fle->destfile = g_strconcat (g_get_tmp_dir (), "/gftp-view.XXXXXX", NULL); new_fle->fd = mkstemps (new_fle->destfile, 0); } if (new_fle->fd < 0) { ftp_log (gftp_logging_error, NULL, _("Error: Cannot open %s for writing: %s\n"), new_fle->destfile, g_strerror (errno)); gftp_file_destroy (new_fle, 1); return; } fchmod (new_fle->fd, S_IRUSR | S_IWUSR); if (is_view) { new_fle->done_view = 1; new_fle->done_rm = 1; } else new_fle->done_edit = 1; newfile = g_list_append (NULL, new_fle); gftpui_common_add_file_transfer (fromwdata->request, towdata->request, fromwdata, towdata, newfile); } }