⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gftpui.c

📁 Linux下使用最为广泛的gftp的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
         N_("Opens a connection to a remote site"), NULL},        {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,         N_("Exit from gFTP"), NULL},        {N_("rename"),  2, gftpui_common_cmd_rename, gftpui_common_request_remote,         N_("Rename a remote file"), NULL},        {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_("site"),    2, gftpui_common_cmd_site, gftpui_common_request_remote,         N_("Run a site specific command"), NULL},        {NULL,          0, NULL,                gftpui_common_request_none,	 NULL, NULL}};intgftpui_common_process_command (void *locui, gftp_request * locreq,                               void *remui, gftp_request * remreq,                               const char *command){  gftp_request * request, * other_request;  void *uidata, *other_uidata;  char *pos, *newstr;  const char *stpos;  size_t cmdlen;  int ret, i;  size_t len;  for (stpos = command; *stpos == ' ' || *stpos == '\t'; stpos++);  newstr = g_strdup (stpos);  len = strlen (newstr);  if (len > 0 && newstr[len - 1] == '\n')    newstr[--len] = '\0';  if (len > 0 && newstr[len - 1] == '\r')    newstr[--len] = '\0';  for (pos = newstr + len - 1;       (*pos == ' ' || *pos == '\t') && pos > newstr;       pos--)    *pos = '\0';  if (*stpos == '\0')    {      g_free (newstr);      return (1);    }  if ((pos = strchr (newstr, ' ')) != NULL)    *pos = '\0';   cmdlen = strlen (newstr);  for (i=0; gftpui_common_commands[i].command != NULL; i++)    {      if (strcmp (gftpui_common_commands[i].command, newstr) == 0)        break;      else if (cmdlen >= gftpui_common_commands[i].minlen &&               strncmp (gftpui_common_commands[i].command, newstr, cmdlen) == 0)        break;     }  if (pos != NULL)    pos++;  else    pos = "";    if (gftpui_common_commands[i].reqtype == gftpui_common_request_local)    {      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 = other_request = NULL;      uidata = other_uidata = NULL;    }   if (gftpui_common_commands[i].command != NULL)    {      ret = gftpui_common_commands[i].func (uidata, request,                                            other_uidata, other_request, pos);      if (request != NULL && !GFTP_IS_CONNECTED (request))        gftpui_disconnect (uidata);    }  else    {      gftpui_common_logfunc (gftp_logging_error, request,                             _("Error: Command not recognized\n"));      ret = 1;    }  g_free (newstr);  return (ret);}gftp_transfer *gftpui_common_add_file_transfer (gftp_request * fromreq, gftp_request * toreq,                                 void *fromuidata, void *touidata,                                 GList * files){  intptr_t append_transfers, one_transfer;  GList * templist, *curfle;  gftp_transfer * tdata;  gftp_file * tempfle;  int show_dialog;    for (templist = files; templist != NULL; templist = templist->next)    {       tempfle = templist->data;      if (tempfle->startsize > 0)        break;    }  show_dialog = templist != NULL;    gftp_lookup_request_option (fromreq, "append_transfers",                              &append_transfers);  gftp_lookup_request_option (fromreq, "one_transfer",                              &one_transfer);  tdata = NULL;  if (append_transfers && one_transfer && !show_dialog)    {      if (g_thread_supported ())        g_static_mutex_lock (&gftpui_common_transfer_mutex);      for (templist = gftp_file_transfers;           templist != NULL;           templist = templist->next)        {          tdata = templist->data;          if (g_thread_supported ())            g_static_mutex_lock (&tdata->structmutex);          if (!compare_request (tdata->fromreq, fromreq, 0) ||              !compare_request (tdata->toreq, toreq, 0) ||              tdata->curfle == NULL)            {              if (g_thread_supported ())                g_static_mutex_unlock (&tdata->structmutex);              continue;            }          tdata->files = g_list_concat (tdata->files, files);          for (curfle = files; curfle != NULL; curfle = curfle->next)            {              tempfle = curfle->data;              if (S_ISDIR (tempfle->st_mode))                tdata->numdirs++;              else                tdata->numfiles++;              if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP)                tdata->total_bytes += tempfle->size;              gftpui_add_file_to_transfer (tdata, curfle);            }          if (g_thread_supported ())            g_static_mutex_unlock (&tdata->structmutex);          break;        }      if (g_thread_supported ())        g_static_mutex_unlock (&gftpui_common_transfer_mutex);    }  else    templist = NULL;  if (templist == NULL)    {      tdata = gftp_tdata_new ();      tdata->fromreq = gftp_copy_request (fromreq);      tdata->toreq = gftp_copy_request (toreq);      tdata->fromwdata = fromuidata;      tdata->towdata = touidata;      if (!show_dialog)        tdata->show = tdata->ready = 1;      tdata->files = files;      for (curfle = files; curfle != NULL; curfle = curfle->next)        {          tempfle = curfle->data;          if (S_ISDIR (tempfle->st_mode))            tdata->numdirs++;          else            tdata->numfiles++;          if (tempfle->transfer_action != GFTP_TRANS_ACTION_SKIP)            tdata->total_bytes += tempfle->size;        }      if (g_thread_supported ())        g_static_mutex_lock (&gftpui_common_transfer_mutex);      gftp_file_transfers = g_list_append (gftp_file_transfers, tdata);      if (g_thread_supported ())        g_static_mutex_unlock (&gftpui_common_transfer_mutex);      if (show_dialog)        gftpui_ask_transfer (tdata);    }  gftpui_start_transfer (tdata);  return (tdata);}static void_gftpui_common_setup_fds (gftp_transfer * tdata, gftp_file * curfle,                          int *fromfd, int *tofd){  *tofd = -1;  *fromfd = -1;  if (curfle->is_fd)    {      if (tdata->toreq->protonum == GFTP_LOCAL_NUM)        *tofd = curfle->fd;      else if (tdata->fromreq->protonum == GFTP_LOCAL_NUM)        *fromfd = curfle->fd;    }}static void_gftpui_common_done_with_fds (gftp_transfer * tdata, gftp_file * curfle){  if (curfle->is_fd)    {      if (tdata->toreq->protonum == GFTP_LOCAL_NUM)        tdata->toreq->datafd = -1;      else        tdata->fromreq->datafd = -1;    }}intgftpui_common_transfer_files (gftp_transfer * tdata){  intptr_t preserve_permissions, preserve_time, trans_blksize;  struct timeval updatetime;  ssize_t num_read, ret;  gftp_file * curfle;   int tofd, fromfd;  char *buf;  gftp_lookup_request_option (tdata->fromreq, "trans_blksize", &trans_blksize);  buf = g_malloc (trans_blksize);  tdata->curfle = tdata->files;  gettimeofday (&tdata->starttime, NULL);  memcpy (&tdata->lasttime, &tdata->starttime, sizeof (tdata->lasttime));  while (tdata->curfle != NULL)    {      num_read = -1;      if (g_thread_supported ())        g_static_mutex_lock (&tdata->structmutex);      curfle = tdata->curfle->data;      tdata->current_file_number++;      if (g_thread_supported ())        g_static_mutex_unlock (&tdata->structmutex);      if (curfle->transfer_action == GFTP_TRANS_ACTION_SKIP)        {          if (g_thread_supported ())            g_static_mutex_lock (&tdata->structmutex);          tdata->next_file = 1;          tdata->curfle = tdata->curfle->next;          if (g_thread_supported ())            g_static_mutex_unlock (&tdata->structmutex);          continue;        }      tdata->tot_file_trans = -1;      if (gftp_connect (tdata->fromreq) == 0 &&          gftp_connect (tdata->toreq) == 0)        {          if (S_ISDIR (curfle->st_mode))            {              if (tdata->toreq->mkdir != NULL)                {                  tdata->toreq->mkdir (tdata->toreq, curfle->destfile);                  if (!GFTP_IS_CONNECTED (tdata->toreq))                    break;                }              if (g_thread_supported ())                g_static_mutex_lock (&tdata->structmutex);              tdata->next_file = 1;              tdata->curfle = tdata->curfle->next;              if (g_thread_supported ())                g_static_mutex_unlock (&tdata->structmutex);              continue;            }          _gftpui_common_setup_fds (tdata, curfle, &fromfd, &tofd);          if (curfle->size == 0)            {              curfle->size = gftp_get_file_size (tdata->fromreq, curfle->file);              tdata->total_bytes += curfle->size;            }          if (GFTP_IS_CONNECTED (tdata->fromreq) &&              GFTP_IS_CONNECTED (tdata->toreq))            {              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,                          curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ?                                                    curfle->startsize : 0);            }        }      if (!GFTP_IS_CONNECTED (tdata->fromreq) ||          !GFTP_IS_CONNECTED (tdata->toreq))        {          tdata->fromreq->logging_function (gftp_logging_misc,                         tdata->fromreq,                         _("Error: Remote site disconnected after trying to transfer file\n"));        }      else if (tdata->tot_file_trans < 0)        {          if (g_thread_supported ())            g_static_mutex_lock (&tdata->structmutex);          curfle->transfer_action = GFTP_TRANS_ACTION_SKIP;          tdata->next_file = 1;          tdata->curfle = tdata->curfle->next;          if (g_thread_supported ())          g_static_mutex_unlock (&tdata->structmutex);          continue;        }      else        {          if (g_thread_supported ())            g_static_mutex_lock (&tdata->structmutex);          tdata->curtrans = 0;          tdata->curresumed = curfle->transfer_action == GFTP_TRANS_ACTION_RESUME ? curfle->startsize : 0;          tdata->resumed_bytes += tdata->curresumed;          if (g_thread_supported ())            g_static_mutex_unlock (&tdata->structmutex);          memset (&updatetime, 0, sizeof (updatetime));          gftpui_start_current_file_in_transfer (tdata);          while (!tdata->cancel &&                 (num_read = gftp_get_next_file_chunk (tdata->fromreq,                                                       buf, trans_blksize)) > 0)            {              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)                {                  num_read = (int) ret;                  break;                }            }          if (num_read == GFTP_ENOTRANS)            num_read = 0;          gftpui_finish_current_file_in_transfer (tdata);        }      if (tdata->cancel)        {          if (gftp_abort_transfer (tdata->fromreq) != 0)            gftp_disconnect (tdata->fromreq);          if (gftp_abort_transfer (tdata->toreq) != 0)            gftp_disconnect (tdata->toreq);        }      else if (num_read < 0)        {          tdata->fromreq->logging_function (gftp_logging_misc,                                        tdata->fromreq,                                        _("Could not download %s from %s\n"),                                        curfle->file,                                        tdata->fromreq->hostname);          if (gftp_get_transfer_status (tdata, num_read) == GFTP_ERETRYABLE)            continue;          break;        }      else        {          _gftpui_common_done_with_fds (tdata, curfle);          if (gftp_end_transfer (tdata->fromreq) != 0)            {              if (gftp_get_transfer_status (tdata, -1) == GFTP_ERETRYABLE)                continue;              break;            }          gftp_end_transfer (tdata->toreq);          tdata->fromreq->logging_function (gftp_logging_misc,                         tdata->fromreq,                         _("Successfully transferred %s at %.2f KB/s\n"),                         curfle->file, tdata->kbs);        }      gftp_lookup_request_option (tdata->fromreq, "preserve_permissions",                                  &preserve_permissions);      gftp_lookup_request_option (tdata->fromreq, "preserve_time",                                  &preserve_time);      if (!curfle->is_fd)        {          if (preserve_permissions && curfle->st_mode != 0)            gftp_chmod (tdata->toreq, curfle->destfile,                        curfle->st_mode & (S_IRWXU | S_IRWXG | S_IRWXO));          if (preserve_time && curfle->datetime != 0)            gftp_set_file_time (tdata->toreq, curfle->destfile,                                curfle->datetime);        }      if (g_thread_supported ())        g_static_mutex_lock (&tdata->structmutex);      tdata->curtrans = 0;      tdata->next_file = 1;      curfle->transfer_done = 1;      tdata->curfle = tdata->curfle->next;      if (g_thread_supported ())        g_static_mutex_unlock (&tdata->structmutex);      if (tdata->cancel && !tdata->skip_file)        break;      tdata->cancel = 0;      tdata->fromreq->cancel = 0;      tdata->toreq->cancel = 0;    }  tdata->done = 1;  g_free (buf);  return (1);}voidgftpui_protocol_update_timeout (gftp_request * request){  intptr_t network_timeout;  gftp_lookup_request_option (request, "network_timeout", &network_timeout);  if (network_timeout > 0)    alarm (network_timeout);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -