/* ftp32.h / ftp32.c ftp library API's for windows95/NT. -----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- Author: Yoshioka Tsuneo(QWF00133@nifty.ne.jp) Welcome any e-mail to me(-: If you can, please send only one email to me that you use this file/program. You can copy,edit,re-distribute this file for any purpose FREE! You can use this file as PDS(Public Domain Software). You can send bugs,hope,etc.. to me with no fee. You can take support service with charging a fee. please consult to me. Thank you for use my program. -----*-----*-----*-----*-----*-----*-----*-----*-----*-----*-----*----- */ #ifndef __FTP32 #define __FTP32 #ifdef __cplusplus extern "C"{ #endif #include #include #include #ifdef WIN32 #include #include #else #include #include #include #include #include #include #define WINAPI #endif #ifndef STRUCT_SOCK #define STRUCT_SOCK typedef struct _SOCK SOCK; /* buffering socket */ #endif #if !defined(_dev_t) && defined(WIN32) #define dev_t _dev_t #define ino_t _ino_t #endif /* file stat from LIST command */ struct ftpstat { /* struct stat member */ dev_t st_dev; ino_t st_ino; unsigned short st_mode; short st_nlink; short st_uid; short st_gid; dev_t st_rdev; off_t st_size; #if defined(_TIMESTRUC_T) && defined(st_atime) /* for IRIX 6.3 */ timestruc_t st_atim; timestruc_t st_mtim; timestruc_t st_ctim; #else time_t st_atime; time_t st_mtime; time_t st_ctime; #endif /* end of struct stract member */ /* ftpstat original member */ char username[256]; char groupname[256]; char filename[1024]; char linkname[1024]; }; /* ftp connection manage struct */ typedef struct _ftpconn{ SOCK *ftpctrl; /* control connection */ SOCK *ftpdata; /* data connection (currently support one data connection only)*/ /* control connection address and port */ struct in_addr ctrlremoteaddr; struct in_addr ctrllocaladdr; int ctrlremoteport; int ctrllocalport; /* data connection address and port */ struct in_addr dataremoteaddr; struct in_addr datalocaladdr; int dataremoteport; int datalocalport; char remotehost[1024]; char user[256]; /* user name for login */ char pass[256]; /* password for login */ int passive; /* passive mode? */ char proxyhost[1024]; int proxytype; /* 0: NONE 1:USER user@hostname 2:OPEN hostname 3: open hostname*/ int proxyport; char cd[1024]; /* current directory */ char type[10]; /* "I" for binary image, "A" for ASCII */ int writing; /* writing(1) or reading(0) for ftpopenfile/ftpread/ftpwrite/ftpclosefile */ struct ftpstat *statlist; /* ftpstat array that contain LIST result (initial =NULL) use by ftpopendir/ftpreaddir/ftpclosedir */ int statlistsize; /* array size of statlist (initial = 0) */ int statlist_current; /* current position of statlist (initial = -1)*/ char osname[100]; /* osname ex: "UNIX" */ int (WINAPI *callbackmsgfunc)(char *msg,void *callbackmsgfuncparam); /* print message to this function */ void *callbackmsgfuncparam; /* parameter for user */ int donesize; /* file size that already send/recieve. */ int msgtime; /* last time that send message to callbackmsgfunc */ int readfilesize; struct stat writefilestat; int checkindex; /* check Index file or not */ int restartoffset; /* begin data transfer from this offset(byte) (resume) */ int resumegetmode; /* support ftp resume when get? */ }ftpconn; #ifndef S_IFLNK #define S_IFLNK 0xA000 #endif #define FTP_CTRL_PORT 21 #define FTP_DATA_PORT 20 /* open socket, connect host, login At first, user must call this function */ ftpconn *ftpopen(const char *host,int port,const char *user,const char *pass); /* connect to ftpserver (automatic called by ftpopen) */ int ftpconnect(ftpconn *ftp); /* close all ftp connection */ int ftpclose(ftpconn *ftp); /* ftpopen() = ftpopen1() + ftpopen2() */ /* allocate ftp struct */ ftpconn *ftpopen1(void); /* open ftp connection */ int ftpopen2(ftpconn *ftp,const char *host,int port,const char *user,const char *pass); /* set proxy server. please call after ftpopen1() and before ftpopen2() */ int ftpsetproxy(ftpconn *ftp,int proxytype,const char *proxyhost,int proxyport); /* set passive/active ftp mode: mode: 0 -> active/normal 1 -> passive 2 -> auto select(passive->active)/DEFAULT */ int ftpsetmode(ftpconn *ftp,int mode); /* manipulate files,directories. return code 0 is success */ int ftpchdir(ftpconn *ftp,const char *path); int ftpmkdir(ftpconn *ftp,const char *path); int ftprmdir(ftpconn *ftp,const char *path); int ftprename(ftpconn *ftp,const char *from,const char *to); int ftpdelete(ftpconn *ftp,const char *path); int ftpsettype(ftpconn *ftp,const char *type); /* restart from pos point. next ftpget()/ftpput()/ftpopenfile() is start from pos. this api is ignored if ftpsetresumemode(,1) is called. */ int ftprestart(ftpconn *ftp,int pos); /* set(1)/unset(0) auto resume mode when ftpget() */ int ftpsetresumegetmode(ftpconn *ftp,int onoff); /* cancel(stop) each command. */ int ftpcancel(ftpconn *ftp); /* print message to callback function. */ int ftpsetcallbackmsgfunc(ftpconn *ftp,int(WINAPI * callbackmsgfunc)(char *msg,void *callbackmsgfuncparam),void *callbackmsgfuncparam); /* send message to callback function */ int ftpcallbackmsg(ftpconn *ftp,char *msg); /* functions for read/write ftpserver's file usage is the same as open/read/write/close function. */ /* mode = "wb"(write binary) or "rb"(read binary) */ int ftpopenfile(ftpconn *ftp,const char *file,const char *mode); int ftpread(ftpconn *ftp,char *buf,int len); int ftpwrite(ftpconn *ftp,const char *buf,int len); int ftpclosefile(ftpconn *ftp); /* get or put file */ /* return code 0 is success */ /* mode = "wb"(write binary) or "rb"(read binary) */ int ftpget(ftpconn *ftp,const char *remotefn,const char *localfn,const char *mode); int ftpput(ftpconn *ftp,const char *remotefn,const char *localfn,const char *mode); /* read directory infomations by "LIST" command */ /* usage is the same as opendir/readdir/closedir functions */ int ftpopendir(ftpconn *ftp,const char *path); struct ftpstat * ftpreaddir(ftpconn *ftp); int ftpclosedir(ftpconn *ftp); #ifdef __cplusplus } #endif #endif /* FTP32 */