资源简介
一个用C语言实现的FTP客户端,包含上传、下载、目录列表、删除、文件列表等功能。
代码片段和文件信息
#if defined(__unix__) || defined(__VMS)
#include
#endif
#if defined(_WIN32)
#include
#endif
#include
#include
#include
#include
#include
#if defined(__unix__)
#include
#include
#include
#include
#include
#include
#elif defined(VMS)
#include
#include
#include
#include
#include
#elif defined(_WIN32)
#include
#endif
#define BUILDING_LIBRARY
#include “ftplib.h“
#if defined(_WIN32)
#define SETSOCKOPT_OPTVAL_TYPE (const char *)
#else
#define SETSOCKOPT_OPTVAL_TYPE (void *)
#endif
#define FTPLIB_BUFSIZ 8192
#define ACCEPT_TIMEOUT 30
#define FTPLIB_CONTROL 0
#define FTPLIB_READ 1
#define FTPLIB_WRITE 2
#if !defined FTPLIB_DEFMODE
#define FTPLIB_DEFMODE FTPLIB_PASSIVE
#endif
struct NetBuf {
char *cput*cget;
int handle; //socket句柄或者叫socket文件描述符
int cavailcleft;
char* buf;
int dir;
netbuf* ctrl;
netbuf* data;
int cmode;
struct timeval idletime;
FtpCallback idlecb;
void* idlearg;
int xfered;
int cbbytes;
int xfered1;
char response[256];
};
#if 0
static char *version =
“ftplib Release 3.1-1 9/16/00 copyright 1996-2000 Thomas Pfau“;
#endif
GLOBALDEF int ftplib_debug = 0;
#if defined(__unix__) || defined(VMS)
#define net_read read
#define net_write write
#define net_close close
#elif defined(_WIN32)
#define net_read(xyz) recv(xyz0)
#define net_write(xyz) send(xyz0)
#define net_close closesocket
#endif
#if defined(NEED_MEMCCPY)
/*! @fuction
**********************************************************************
*
* 函数名:memccpy
* 功能: VAX C不支持memccpy,所以我们自己提供一个memccpy的实现
* 作者: 周沛沛
*
*********************************************************************/
void *memccpy(void *dest const void *src int c size_t n)
{
int i=0;
const unsigned char *ip=src;
unsigned char *op=dest;
while (i < n)
{
if ((*op++ = *ip++) == c)
break;
i++;
}
if (i == n)
return NULL;
return op;
}
#endif
#if defined(NEED_STRDUP)
/*! @fuction
**********************************************************************
*
* 函数名:memccpy
* 功能: VAX C不支持strdup,所以我们自己提供一个strdup的实现
* 作者: 周沛沛
*
*********************************************************************/
char *strdup(const char *src)
{
int l = strlen(src) + 1;
char *dst = malloc(l);
if (dst)
strcpy(dstsrc);
return dst;
}
#endif
/*
* socket_wait - wait for socket to receive or flush data
*
* return 1 if no user callback otherwise return value returned by
* user callback
*/
static int socket_wait(netbuf *ctl)
{
fd_set fd*rfd = NULL*wfd = NULL;
struct timeval tv;
int rv = 0;
if ((ctl->di
- 上一篇:图像点运算VC++程序
- 下一篇:MFC综合实战项目
评论
共有 条评论