The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ftplib.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _FTPLIB_NO_COMPAT
 
#define FTPLIB_ASCII   'A'
 
#define FTPLIB_BINARY   FTPLIB_IMAGE
 
#define FTPLIB_CALLBACK   2
 
#define FTPLIB_CALLBACK_WRITER   6
 
#define FTPLIB_CALLBACK_WRITERARG   7
 
#define FTPLIB_CALLBACKARG   4
 
#define FTPLIB_CALLBACKBYTES   5
 
#define FTPLIB_CONNMODE   1
 
#define FTPLIB_DIR   1
 
#define FTPLIB_DIR_VERBOSE   2
 
#define FTPLIB_FILE_READ   3
 
#define FTPLIB_FILE_WRITE   4
 
#define FTPLIB_IDLETIME   3
 
#define FTPLIB_IMAGE   'I'
 
#define FTPLIB_PASSIVE   1
 
#define FTPLIB_PORT   2
 
#define FTPLIB_TEXT   FTPLIB_ASCII
 

Typedefs

typedef int(* FtpCallback )(netbuf *nControl, int xfered, void *arg)
 
typedef int(* FtpCallbackWriter )(netbuf *nControl, const void *buffer, size_t size, void *arg)
 
typedef struct NetBuf netbuf
 

Functions

GLOBALREF int FtpAccess (const char *path, int typ, int mode, netbuf *nControl, netbuf **nData)
 
GLOBALREF int FtpCDUp (netbuf *nControl)
 
GLOBALREF int FtpChdir (const char *path, netbuf *nControl)
 
GLOBALREF int FtpClose (netbuf *nData)
 
GLOBALREF int FtpConnect (const char *host, netbuf **nControl)
 
GLOBALREF int FtpDelete (const char *fnm, netbuf *nControl)
 
GLOBALREF int FtpDir (const char *output, const char *path, netbuf *nControl)
 
GLOBALREF int FtpGet (const char *output, const char *path, char mode, netbuf *nControl)
 
GLOBALREF void FtpInit (void)
 
GLOBALREF char * FtpLastResponse (netbuf *nControl)
 
GLOBALREF int FtpLogin (const char *user, const char *pass, netbuf *nControl)
 
GLOBALREF int FtpMkdir (const char *path, netbuf *nControl)
 
GLOBALREF int FtpModDate (const char *path, char *dt, int max, netbuf *nControl)
 
GLOBALREF int FtpNlst (const char *output, const char *path, netbuf *nControl)
 
GLOBALREF int FtpOptions (int opt, long val, netbuf *nControl)
 
GLOBALREF int FtpPut (const char *input, const char *path, char mode, netbuf *nControl)
 
GLOBALREF int FtpPwd (char *path, int max, netbuf *nControl)
 
GLOBALREF void FtpQuit (netbuf *nControl)
 
GLOBALREF int FtpRead (void *buf, int max, netbuf *nData)
 
GLOBALREF int FtpRename (const char *src, const char *dst, netbuf *nControl)
 
GLOBALREF int FtpRmdir (const char *path, netbuf *nControl)
 
GLOBALREF int FtpSite (const char *cmd, netbuf *nControl)
 
GLOBALREF int FtpSize (const char *path, int *size, char mode, netbuf *nControl)
 
GLOBALREF int FtpSysType (char *buf, int max, netbuf *nControl)
 
GLOBALREF int FtpWrite (void *buf, int len, netbuf *nData)
 

Variables

GLOBALREF int ftplib_debug
 

Macro Definition Documentation

#define _FTPLIB_NO_COMPAT

Definition at line 27 of file ftplib.h.

#define FTPLIB_ASCII   'A'

Definition at line 50 of file ftplib.h.

#define FTPLIB_BINARY   FTPLIB_IMAGE

Definition at line 53 of file ftplib.h.

#define FTPLIB_CALLBACK   2

Definition at line 60 of file ftplib.h.

#define FTPLIB_CALLBACK_WRITER   6

Definition at line 64 of file ftplib.h.

#define FTPLIB_CALLBACK_WRITERARG   7

Definition at line 65 of file ftplib.h.

#define FTPLIB_CALLBACKARG   4

Definition at line 62 of file ftplib.h.

#define FTPLIB_CALLBACKBYTES   5

Definition at line 63 of file ftplib.h.

#define FTPLIB_CONNMODE   1

Definition at line 59 of file ftplib.h.

#define FTPLIB_DIR   1

Definition at line 44 of file ftplib.h.

#define FTPLIB_DIR_VERBOSE   2

Definition at line 45 of file ftplib.h.

#define FTPLIB_FILE_READ   3

Definition at line 46 of file ftplib.h.

#define FTPLIB_FILE_WRITE   4

Definition at line 47 of file ftplib.h.

#define FTPLIB_IDLETIME   3

Definition at line 61 of file ftplib.h.

#define FTPLIB_IMAGE   'I'

Definition at line 51 of file ftplib.h.

#define FTPLIB_PASSIVE   1

Definition at line 56 of file ftplib.h.

#define FTPLIB_PORT   2

Definition at line 57 of file ftplib.h.

#define FTPLIB_TEXT   FTPLIB_ASCII

Definition at line 52 of file ftplib.h.

Typedef Documentation

typedef int(* FtpCallback)(netbuf *nControl, int xfered, void *arg)

Definition at line 72 of file ftplib.h.

typedef int(* FtpCallbackWriter)(netbuf *nControl, const void *buffer, size_t size, void *arg)

Definition at line 73 of file ftplib.h.

typedef struct NetBuf netbuf

Definition at line 71 of file ftplib.h.

Function Documentation

GLOBALREF int FtpAccess ( const char *  path,
int  typ,
int  mode,
netbuf nControl,
netbuf **  nData 
)

Definition at line 920 of file ftplib.c.

922 {
923  char buf[256];
924  int dir;
925  if ((path == NULL) &&
926  ((typ == FTPLIB_FILE_WRITE) || (typ == FTPLIB_FILE_READ)))
927  {
928  sprintf(nControl->response,
929  "Missing path argument for file transfer\n");
930  return 0;
931  }
932  sprintf(buf, "TYPE %c", mode);
933  if (!FtpSendCmd(buf, '2', nControl))
934  return 0;
935  switch (typ)
936  {
937  case FTPLIB_DIR:
938  strcpy(buf,"NLST");
939  dir = FTPLIB_READ;
940  break;
941  case FTPLIB_DIR_VERBOSE:
942  strcpy(buf,"LIST");
943  dir = FTPLIB_READ;
944  break;
945  case FTPLIB_FILE_READ:
946  strcpy(buf,"RETR");
947  dir = FTPLIB_READ;
948  break;
949  case FTPLIB_FILE_WRITE:
950  strcpy(buf,"STOR");
951  dir = FTPLIB_WRITE;
952  break;
953  default:
954  sprintf(nControl->response, "Invalid open type %d\n", typ);
955  return 0;
956  }
957  if (path != NULL)
958  {
959  int i = (int)strlen(buf);
960  buf[i++] = ' ';
961  if ((strlen(path) + i) >= sizeof(buf))
962  return 0;
963  strcpy(&buf[i],path);
964  }
965  if (FtpOpenPort(nControl, nData, mode, dir) == -1)
966  return 0;
967  if (!FtpSendCmd(buf, '1', nControl))
968  {
969  FtpClose(*nData);
970  *nData = NULL;
971  return 0;
972  }
973  (*nData)->ctrl = nControl;
974  nControl->data = *nData;
975  if (nControl->cmode == FTPLIB_PORT)
976  {
977  if (!FtpAcceptConnection(*nData,nControl))
978  {
979  FtpClose(*nData);
980  *nData = NULL;
981  nControl->data = NULL;
982  return 0;
983  }
984  }
985  return 1;
986 }
static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir)
Definition: ftplib.c:698
int cmode
Definition: ftplib.c:131
GLOBALDEF int FtpClose(netbuf *nData)
Definition: ftplib.c:1054
#define FTPLIB_DIR
Definition: ftplib.h:44
#define FTPLIB_DIR_VERBOSE
Definition: ftplib.h:45
#define FTPLIB_PORT
Definition: ftplib.h:57
#define FTPLIB_READ
Definition: ftplib.c:80
#define FTPLIB_FILE_READ
Definition: ftplib.h:46
#define FTPLIB_FILE_WRITE
Definition: ftplib.h:47
return NULL
Definition: regex.c:7953
#define FTPLIB_WRITE
Definition: ftplib.c:81
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
netbuf * data
Definition: ftplib.c:130
char response[256]
Definition: ftplib.c:140
static int FtpAcceptConnection(netbuf *nData, netbuf *nControl)
Definition: ftplib.c:847
GLOBALREF int FtpCDUp ( netbuf nControl)

Definition at line 1168 of file ftplib.c.

1169 {
1170  if (!FtpSendCmd("CDUP",'2',nControl))
1171  return 0;
1172  return 1;
1173 }
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
GLOBALREF int FtpChdir ( const char *  path,
netbuf nControl 
)

Definition at line 1151 of file ftplib.c.

1152 {
1153  char buf[256];
1154 
1155  if ((strlen(path) + 6) > sizeof(buf))
1156  return 0;
1157  sprintf(buf,"CWD %s",path);
1158  if (!FtpSendCmd(buf,'2',nControl))
1159  return 0;
1160  return 1;
1161 }
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
GLOBALREF int FtpClose ( netbuf nData)

Definition at line 1054 of file ftplib.c.

1055 {
1056  netbuf *ctrl;
1057  switch (nData->dir)
1058  {
1059  case FTPLIB_WRITE:
1060  /* potential problem - if buffer flush fails, how to notify user? */
1061  if (nData->buf != NULL)
1062  writeline(NULL, 0, nData);
1063  case FTPLIB_READ:
1064  if (nData->buf)
1065  free(nData->buf);
1066  shutdown(nData->handle,2);
1067  net_close(nData->handle);
1068  ctrl = nData->ctrl;
1069  free(nData);
1070  if (ctrl)
1071  {
1072  ctrl->data = NULL;
1073  return(readresp('2', ctrl));
1074  }
1075  return 1;
1076  case FTPLIB_CONTROL:
1077  if (nData->data)
1078  {
1079  nData->ctrl = NULL;
1080  FtpClose(nData);
1081  }
1082  net_close(nData->handle);
1083  free(nData);
1084  return 0;
1085  }
1086  return 1;
1087 }
Definition: ftplib.c:123
GLOBALDEF int FtpClose(netbuf *nData)
Definition: ftplib.c:1054
int dir
Definition: ftplib.c:128
int handle
Definition: ftplib.c:125
netbuf * ctrl
Definition: ftplib.c:129
#define FTPLIB_READ
Definition: ftplib.c:80
static int readresp(char c, netbuf *nControl)
Definition: ftplib.c:381
return NULL
Definition: regex.c:7953
free(preg->fastmap)
#define FTPLIB_WRITE
Definition: ftplib.c:81
static int writeline(char *buf, int len, netbuf *nData)
Definition: ftplib.c:317
netbuf * data
Definition: ftplib.c:130
char * buf
Definition: ftplib.c:127
#define FTPLIB_CONTROL
Definition: ftplib.c:79
GLOBALREF int FtpConnect ( const char *  host,
netbuf **  nControl 
)

Definition at line 444 of file ftplib.c.

445 {
446  int sControl, stat, flags, oldflags;
447  struct sockaddr_in sin;
448  struct hostent *phe;
449  struct servent *pse;
450  int on=1;
451  netbuf *ctrl;
452  char *lhost;
453  char *pnum;
454  struct timeval tv;
455  fd_set wr;
456 
457  memset(&sin,0,sizeof(sin));
458  sin.sin_family = AF_INET;
459  lhost = strdup(host);
460  pnum = strchr(lhost,':');
461  if (pnum == NULL)
462  {
463 #if defined(VMS) || defined(ANDROID)
464  sin.sin_port = htons(21);
465 #else
466  if ((pse = getservbyname("ftp","tcp")) == NULL)
467  {
468  perror("getservbyname");
469  return 0;
470  }
471  sin.sin_port = pse->s_port;
472 #endif
473  }
474  else
475  {
476  *pnum++ = '\0';
477  if (isdigit(*pnum))
478  sin.sin_port = htons(atoi(pnum));
479  else
480  {
481  pse = getservbyname(pnum,"tcp");
482  sin.sin_port = pse->s_port;
483  }
484  }
485  if ((sin.sin_addr.s_addr = inet_addr(lhost)) == -1)
486  {
487  if ((phe = gethostbyname(lhost)) == NULL)
488  {
489  perror("gethostbyname");
490  return 0;
491  }
492 
493  memcpy((char *)&sin.sin_addr, phe->h_addr, phe->h_length);
494 
495  }
496  free(lhost);
497 
498  sControl = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
499  if (sControl == -1)
500  {
501  perror("socket");
502  return 0;
503  }
504 
505  if ( setsockopt(sControl,SOL_SOCKET,SO_REUSEADDR,
506  SETSOCKOPT_OPTVAL_TYPE &on, sizeof(on)) == -1)
507  {
508  perror("setsockopt");
509  net_close(sControl);
510  return 0;
511  }
512 
513 #if defined(_WIN32)
514  if (connect(sControl, (struct sockaddr *)&sin, sizeof(sin)) == -1)
515  {
516  perror("connect");
517  net_close(sControl);
518  return 0;
519  }
520 #else
521  //set nonblocking for connection timeout
522  flags = fcntl( sControl, F_GETFL,0);
523  oldflags=flags;
524  fcntl( sControl, F_SETFL, O_NONBLOCK|flags);
525 
526  stat=connect( sControl, (struct sockaddr *)&sin, sizeof(sin));
527  if (stat < 0)
528  {
529  if (errno != EWOULDBLOCK && errno != EINPROGRESS)
530  {
531  perror("connect");
532  net_close(sControl);
533  return 0;
534  }
535  }
536 
537  FD_ZERO(&wr);
538  FD_SET( sControl, &wr);
539 
540  tv.tv_sec = ACCEPT_TIMEOUT;
541  tv.tv_usec = 0;
542 
543  stat = select(sControl+1, 0, &wr, 0, &tv);
544 
545  if (stat < 1)
546  {
547  // time out has expired,
548  // or an error has ocurred
549  perror("timeout");
550  net_close(sControl);
551  return 0;
552  }
553 
554  if (ftplib_debug > 1)
555  printf("connected\n");
556 
557  //set original flags
558  fcntl( sControl, F_SETFL, oldflags);
559 #endif
560 
561  ctrl = calloc(1,sizeof(netbuf));
562  if (ctrl == NULL)
563  {
564  perror("calloc");
565  net_close(sControl);
566  return 0;
567  }
568  ctrl->buf = malloc(FTPLIB_BUFSIZ);
569  if (ctrl->buf == NULL)
570  {
571  perror("calloc");
572  net_close(sControl);
573  free(ctrl);
574  return 0;
575  }
576  ctrl->handle = sControl;
577  ctrl->dir = FTPLIB_CONTROL;
578  ctrl->ctrl = NULL;
579  ctrl->cmode = FTPLIB_DEFMODE;
580  ctrl->idlecb = NULL;
581  ctrl->writercb = NULL;
582  ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
583  ctrl->idlearg = NULL;
584  ctrl->writerarg = NULL;
585  ctrl->xfered = 0;
586  ctrl->xfered1 = 0;
587  ctrl->cbbytes = 0;
588  if (readresp('2', ctrl) == 0)
589  {
590  net_close(sControl);
591  free(ctrl->buf);
592  free(ctrl);
593  return 0;
594  }
595  *nControl = ctrl;
596  return 1;
597 }
int cmode
Definition: ftplib.c:131
Definition: ftplib.c:123
void * idlearg
Definition: ftplib.c:135
int dir
Definition: ftplib.c:128
int xfered1
Definition: ftplib.c:139
int handle
Definition: ftplib.c:125
netbuf * ctrl
Definition: ftplib.c:129
FtpCallbackWriter writercb
Definition: ftplib.c:134
static int readresp(char c, netbuf *nControl)
Definition: ftplib.c:381
FtpCallback idlecb
Definition: ftplib.c:133
#define SETSOCKOPT_OPTVAL_TYPE
Definition: ftplib.c:73
char * malloc()
return NULL
Definition: regex.c:7953
GLOBALDEF int ftplib_debug
Definition: ftplib.c:148
free(preg->fastmap)
#define ACCEPT_TIMEOUT
Definition: ftplib.c:77
int xfered
Definition: ftplib.c:137
struct timeval idletime
Definition: ftplib.c:132
#define FTPLIB_DEFMODE
Definition: ftplib.c:84
void * writerarg
Definition: ftplib.c:136
char * buf
Definition: ftplib.c:127
int cbbytes
Definition: ftplib.c:138
#define FTPLIB_CONTROL
Definition: ftplib.c:79
#define FTPLIB_BUFSIZ
Definition: ftplib.c:76
GLOBALREF int FtpDelete ( const char *  fnm,
netbuf nControl 
)

Definition at line 1397 of file ftplib.c.

1398 {
1399  char cmd[256];
1400 
1401  if ((strlen(fnm) + 7) > sizeof(cmd))
1402  return 0;
1403  sprintf(cmd,"DELE %s",fnm);
1404  if (!FtpSendCmd(cmd,'2', nControl))
1405  return 0;
1406  return 1;
1407 }
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
GLOBALREF int FtpDir ( const char *  output,
const char *  path,
netbuf nControl 
)

Definition at line 1296 of file ftplib.c.

1297 {
1298  return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII);
1299 }
#define FTPLIB_DIR_VERBOSE
Definition: ftplib.h:45
#define FTPLIB_ASCII
Definition: ftplib.h:50
static int FtpXfer(const char *localfile, const char *path, netbuf *nControl, int typ, int mode)
Definition: ftplib.c:1219
GLOBALREF int FtpGet ( const char *  output,
const char *  path,
char  mode,
netbuf nControl 
)

Definition at line 1354 of file ftplib.c.

1356 {
1357  return FtpXfer(outputfile, path, nControl, FTPLIB_FILE_READ, mode);
1358 }
#define FTPLIB_FILE_READ
Definition: ftplib.h:46
static int FtpXfer(const char *localfile, const char *path, netbuf *nControl, int typ, int mode)
Definition: ftplib.c:1219
GLOBALREF void FtpInit ( void  )

Definition at line 416 of file ftplib.c.

417 {
418 #if defined(_WIN32)
419  WORD wVersionRequested;
420  WSADATA wsadata;
421  int err;
422  wVersionRequested = MAKEWORD(1,1);
423  if ((err = WSAStartup(wVersionRequested,&wsadata)) != 0)
424  if (ftplib_debug > 1)
425  fprintf(stderr,"Network failed to start: %d\n",err);
426 #endif
427 }
GLOBALDEF int ftplib_debug
Definition: ftplib.c:148
GLOBALREF char* FtpLastResponse ( netbuf nControl)

Definition at line 432 of file ftplib.c.

433 {
434  if ((nControl) && (nControl->dir == FTPLIB_CONTROL))
435  return nControl->response;
436  return NULL;
437 }
int dir
Definition: ftplib.c:128
return NULL
Definition: regex.c:7953
char response[256]
Definition: ftplib.c:140
#define FTPLIB_CONTROL
Definition: ftplib.c:79
GLOBALREF int FtpLogin ( const char *  user,
const char *  pass,
netbuf nControl 
)

Definition at line 675 of file ftplib.c.

676 {
677  char tempbuf[64];
678 
679  if (((strlen(user) + 7) > sizeof(tempbuf)) ||
680  ((strlen(pass) + 7) > sizeof(tempbuf)))
681  return 0;
682  sprintf(tempbuf,"USER %s",user);
683  if (!FtpSendCmd(tempbuf,'3',nControl))
684  {
685  if (nControl->response[0] == '2')
686  return 1;
687  return 0;
688  }
689  sprintf(tempbuf,"PASS %s",pass);
690  return FtpSendCmd(tempbuf,'2',nControl);
691 }
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
char response[256]
Definition: ftplib.c:140
GLOBALREF int FtpMkdir ( const char *  path,
netbuf nControl 
)

Definition at line 1134 of file ftplib.c.

1135 {
1136  char buf[256];
1137 
1138  if ((strlen(path) + 6) > sizeof(buf))
1139  return 0;
1140  sprintf(buf,"MKD %s",path);
1141  if (!FtpSendCmd(buf,'2', nControl))
1142  return 0;
1143  return 1;
1144 }
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
GLOBALREF int FtpModDate ( const char *  path,
char *  dt,
int  max,
netbuf nControl 
)

Definition at line 1334 of file ftplib.c.

1335 {
1336  char buf[256];
1337  int rv = 1;
1338 
1339  if ((strlen(path) + 7) > sizeof(buf))
1340  return 0;
1341  sprintf(buf,"MDTM %s",path);
1342  if (!FtpSendCmd(buf,'2',nControl))
1343  rv = 0;
1344  else
1345  strncpy(dt, &nControl->response[4], max);
1346  return rv;
1347 }
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
char response[256]
Definition: ftplib.c:140
GLOBALREF int FtpNlst ( const char *  output,
const char *  path,
netbuf nControl 
)

Definition at line 1285 of file ftplib.c.

1287 {
1288  return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII);
1289 }
#define FTPLIB_DIR
Definition: ftplib.h:44
#define FTPLIB_ASCII
Definition: ftplib.h:50
static int FtpXfer(const char *localfile, const char *path, netbuf *nControl, int typ, int mode)
Definition: ftplib.c:1219
GLOBALREF int FtpOptions ( int  opt,
long  val,
netbuf nControl 
)

Definition at line 604 of file ftplib.c.

605 {
606  int v,rv=0;
607  switch (opt)
608  {
609  case FTPLIB_CONNMODE:
610  v = (int) val;
611  if ((v == FTPLIB_PASSIVE) || (v == FTPLIB_PORT))
612  {
613  nControl->cmode = v;
614  rv = 1;
615  }
616  break;
617  case FTPLIB_CALLBACK:
618  nControl->idlecb = (FtpCallback) val;
619  rv = 1;
620  break;
622  nControl->writercb = (FtpCallbackWriter) val;
623  rv = 1;
624  break;
625  case FTPLIB_IDLETIME:
626  v = (int) val;
627  rv = 1;
628  nControl->idletime.tv_sec = v / 1000;
629  nControl->idletime.tv_usec = (v % 1000) * 1000;
630  break;
631  case FTPLIB_CALLBACKARG:
632  rv = 1;
633  nControl->idlearg = (void *) val;
634  break;
636  rv = 1;
637  nControl->writerarg = (void *) val;
638  break;
640  rv = 1;
641  nControl->cbbytes = (int) val;
642  break;
643  }
644  return rv;
645 }
int cmode
Definition: ftplib.c:131
#define FTPLIB_CALLBACK
Definition: ftplib.h:60
int(* FtpCallbackWriter)(netbuf *nControl, const void *buffer, size_t size, void *arg)
Definition: ftplib.h:73
void * idlearg
Definition: ftplib.c:135
#define FTPLIB_CALLBACK_WRITER
Definition: ftplib.h:64
#define FTPLIB_CALLBACK_WRITERARG
Definition: ftplib.h:65
FtpCallbackWriter writercb
Definition: ftplib.c:134
#define FTPLIB_PORT
Definition: ftplib.h:57
FtpCallback idlecb
Definition: ftplib.c:133
struct timeval idletime
Definition: ftplib.c:132
#define FTPLIB_PASSIVE
Definition: ftplib.h:56
void * writerarg
Definition: ftplib.c:136
#define FTPLIB_IDLETIME
Definition: ftplib.h:61
int(* FtpCallback)(netbuf *nControl, int xfered, void *arg)
Definition: ftplib.h:72
#define FTPLIB_CALLBACKARG
Definition: ftplib.h:62
#define FTPLIB_CONNMODE
Definition: ftplib.h:59
int cbbytes
Definition: ftplib.c:138
#define FTPLIB_CALLBACKBYTES
Definition: ftplib.h:63
GLOBALREF int FtpPut ( const char *  input,
const char *  path,
char  mode,
netbuf nControl 
)

Definition at line 1365 of file ftplib.c.

1367 {
1368  return FtpXfer(inputfile, path, nControl, FTPLIB_FILE_WRITE, mode);
1369 }
#define FTPLIB_FILE_WRITE
Definition: ftplib.h:47
static int FtpXfer(const char *localfile, const char *path, netbuf *nControl, int typ, int mode)
Definition: ftplib.c:1219
GLOBALREF int FtpPwd ( char *  path,
int  max,
netbuf nControl 
)

Definition at line 1197 of file ftplib.c.

1198 {
1199  int l = max;
1200  char *b = path;
1201  char *s;
1202  if (!FtpSendCmd("PWD",'2',nControl))
1203  return 0;
1204  s = strchr(nControl->response, '"');
1205  if (s == NULL)
1206  return 0;
1207  s++;
1208  while ((--l) && (*s) && (*s != '"'))
1209  *b++ = *s++;
1210  *b++ = '\0';
1211  return 1;
1212 }
return NULL
Definition: regex.c:7953
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
char response[256]
Definition: ftplib.c:140
GLOBALREF void FtpQuit ( netbuf nControl)

Definition at line 1414 of file ftplib.c.

1415 {
1416  if (nControl->dir != FTPLIB_CONTROL)
1417  return;
1418  FtpSendCmd("QUIT",'2',nControl);
1419  net_close(nControl->handle);
1420  free(nControl->buf);
1421  free(nControl);
1422 }
int dir
Definition: ftplib.c:128
int handle
Definition: ftplib.c:125
free(preg->fastmap)
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
char * buf
Definition: ftplib.c:127
#define FTPLIB_CONTROL
Definition: ftplib.c:79
GLOBALREF int FtpRead ( void *  buf,
int  max,
netbuf nData 
)

Definition at line 991 of file ftplib.c.

992 {
993  int i;
994  if (nData->dir != FTPLIB_READ)
995  return 0;
996  if (nData->buf)
997  i = readline(buf, max, nData);
998  else
999  {
1000  i = socket_wait(nData);
1001  if (i != 1)
1002  return 0;
1003  i = (int)net_read(nData->handle, buf, max);
1004  }
1005  if (i == -1)
1006  return 0;
1007  nData->xfered += i;
1008  if (nData->idlecb && nData->cbbytes)
1009  {
1010  nData->xfered1 += i;
1011  if (nData->xfered1 > nData->cbbytes)
1012  {
1013  if (nData->idlecb(nData, nData->xfered, nData->idlearg) == 0)
1014  return 0;
1015  nData->xfered1 = 0;
1016  }
1017  }
1018  return i;
1019 }
void * idlearg
Definition: ftplib.c:135
int dir
Definition: ftplib.c:128
int xfered1
Definition: ftplib.c:139
int handle
Definition: ftplib.c:125
static int readline(char *buf, int max, netbuf *ctl)
Definition: ftplib.c:240
#define FTPLIB_READ
Definition: ftplib.c:80
FtpCallback idlecb
Definition: ftplib.c:133
int xfered
Definition: ftplib.c:137
char * buf
Definition: ftplib.c:127
static int socket_wait(netbuf *ctl)
Definition: ftplib.c:201
int cbbytes
Definition: ftplib.c:138
GLOBALREF int FtpRename ( const char *  src,
const char *  dst,
netbuf nControl 
)

Definition at line 1376 of file ftplib.c.

1377 {
1378  char cmd[256];
1379 
1380  if (((strlen(src) + 7) > sizeof(cmd)) ||
1381  ((strlen(dst) + 7) > sizeof(cmd)))
1382  return 0;
1383  sprintf(cmd,"RNFR %s",src);
1384  if (!FtpSendCmd(cmd,'3',nControl))
1385  return 0;
1386  sprintf(cmd,"RNTO %s",dst);
1387  if (!FtpSendCmd(cmd,'2',nControl))
1388  return 0;
1389  return 1;
1390 }
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
GLOBALREF int FtpRmdir ( const char *  path,
netbuf nControl 
)

Definition at line 1180 of file ftplib.c.

1181 {
1182  char buf[256];
1183 
1184  if ((strlen(path) + 6) > sizeof(buf))
1185  return 0;
1186  sprintf(buf,"RMD %s",path);
1187  if (!FtpSendCmd(buf,'2',nControl))
1188  return 0;
1189  return 1;
1190 }
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
GLOBALREF int FtpSite ( const char *  cmd,
netbuf nControl 
)

Definition at line 1094 of file ftplib.c.

1095 {
1096  char buf[256];
1097 
1098  if ((strlen(cmd) + 7) > sizeof(buf))
1099  return 0;
1100  sprintf(buf,"SITE %s",cmd);
1101  if (!FtpSendCmd(buf,'2',nControl))
1102  return 0;
1103  return 1;
1104 }
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
GLOBALREF int FtpSize ( const char *  path,
int *  size,
char  mode,
netbuf nControl 
)

Definition at line 1306 of file ftplib.c.

1307 {
1308  char cmd[256];
1309  int resp,sz,rv=1;
1310 
1311  if ((strlen(path) + 7) > sizeof(cmd))
1312  return 0;
1313  sprintf(cmd, "TYPE %c", mode);
1314  if (!FtpSendCmd(cmd, '2', nControl))
1315  return 0;
1316  sprintf(cmd,"SIZE %s",path);
1317  if (!FtpSendCmd(cmd,'2',nControl))
1318  rv = 0;
1319  else
1320  {
1321  if (sscanf(nControl->response, "%d %d", &resp, &sz) == 2)
1322  *size = sz;
1323  else
1324  rv = 0;
1325  }
1326  return rv;
1327 }
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
int size
Definition: regex.c:5043
char response[256]
Definition: ftplib.c:140
GLOBALREF int FtpSysType ( char *  buf,
int  max,
netbuf nControl 
)

Definition at line 1115 of file ftplib.c.

1116 {
1117  int l = max;
1118  char *b = buf;
1119  char *s;
1120  if (!FtpSendCmd("SYST",'2',nControl))
1121  return 0;
1122  s = &nControl->response[4];
1123  while ((--l) && (*s != ' '))
1124  *b++ = *s++;
1125  *b++ = '\0';
1126  return 1;
1127 }
static int FtpSendCmd(const char *cmd, char expresp, netbuf *nControl)
Definition: ftplib.c:652
char response[256]
Definition: ftplib.c:140
GLOBALREF int FtpWrite ( void *  buf,
int  len,
netbuf nData 
)

Definition at line 1024 of file ftplib.c.

1025 {
1026  int i;
1027  if (nData->dir != FTPLIB_WRITE)
1028  return 0;
1029  if (nData->buf)
1030  i = writeline(buf, len, nData);
1031  else
1032  {
1033  socket_wait(nData);
1034  i = (int)net_write(nData->handle, buf, len);
1035  }
1036  if (i == -1)
1037  return 0;
1038  nData->xfered += i;
1039  if (nData->idlecb && nData->cbbytes)
1040  {
1041  nData->xfered1 += i;
1042  if (nData->xfered1 > nData->cbbytes)
1043  {
1044  nData->idlecb(nData, nData->xfered, nData->idlearg);
1045  nData->xfered1 = 0;
1046  }
1047  }
1048  return i;
1049 }
void * idlearg
Definition: ftplib.c:135
int dir
Definition: ftplib.c:128
int xfered1
Definition: ftplib.c:139
int handle
Definition: ftplib.c:125
FtpCallback idlecb
Definition: ftplib.c:133
#define FTPLIB_WRITE
Definition: ftplib.c:81
int xfered
Definition: ftplib.c:137
static int writeline(char *buf, int len, netbuf *nData)
Definition: ftplib.c:317
char * buf
Definition: ftplib.c:127
static int socket_wait(netbuf *ctl)
Definition: ftplib.c:201
int cbbytes
Definition: ftplib.c:138

Variable Documentation

GLOBALREF int ftplib_debug

Definition at line 97 of file ftplib.h.