1 /*$Id: jftp.h,v 1.27 2000/04/04 21:13:52 jens Exp $*/
2 /*
3  * Copyright (c) 1997, 1998, 1999
4  *      Jens A. Nilsson, jnilsson@ludd.luth.se. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef JFTP_H
29 #define JFTP_H
30 
31 #define JFTP_MAX_LINE    1024
32 #define JFTP_BUF         16384
33 #define JFTP_PORT_LEN    40
34 #define JFTP_TIMEOUT_VAL 120
35 #define JFTP_BROKEN      1
36 #define JFTP_UNKNOWNHOST 2
37 #define JFTP_CONFUSED    3
38 #define JFTP_WRITEERR    4
39 #define JFTP_TIMEOUT     5
40 #define JFTP_ERR         6
41 #define JFTP_ERRNO       7
42 
43 #define JFTP_TEMPFILE	"jftp-dir.XXXXXX"
44 #define JFTP_DIR    	"/tmp"
45 
46 #define	JFTP_RESPONSE " "
47 
48 struct ftp_con {
49 	int		ftp_com;
50 	int		ftp_data;
51 	int		ftp_listen;
52 	int		ftp_family;
53 	char	*ftp_remote_host;
54 	char	*ftp_user_name;
55 	char	*ftp_password;
56 	char	*ftp_remote_dir;
57 	FILE	*ftp_logfile;
58 	char	ftp_buf[JFTP_BUF];
59 	char	*ftp_tempdir;
60 	int		ftp_retries;
61 	int		ftp_timeout;
62 	int		ftp_timed_out;
63 	int		ftp_port;
64 	int		ftp_verbose;
65 	int		ftp_passive;
66 	int		ftp_resp;
67 #ifdef NO_QUADS
68 	unsigned long ftp_recd;
69 	unsigned long ftp_sent;
70 #else
71 	u_int64_t ftp_recd;
72 	u_int64_t ftp_sent;
73 #endif
74 	int		ftp_relogins;
75 	int		ftp_downloads;
76 	int		ftp_timeouts;
77 };
78 /*
79  * Differnet values of ftp_verbose:
80  *	0	ftp is quiet
81  *	1	ftp leaves error messages in logfile
82  *	2	ftp SHOUTS in logfile
83  */
84 
85 
86 /* Login on server, returns NULL on failure */
87 struct ftp_con * ftp_login(char *host, int port, int family, char *username,
88 			char *password, FILE * logfile, int verbose);
89 
90 void ftp_unalloc(struct ftp_con *);
91 
92 /* Login to the same server again */
93 int 	ftp_relogin(struct ftp_con *);
94 
95 /* List dir, returns NULL on failure */
96 char 	*ftp_dir(struct ftp_con *, const char *dir);
97 
98 /* List current ftp_dir recursive, returns NULL on failure */
99 char 	*ftp_dir_recurs(struct ftp_con *, char *tempfile);
100 
101 /* Change directory on server to ftp_dir */
102 int		ftp_cd(struct ftp_con *, const char *dir);
103 
104 /* Copy remote_file to local_file, if seekto is nonzero start at byte seekto */
105 int		ftp_get(struct ftp_con *, char *local_file, char *remote_file,
106 			size_t seekto);
107 
108 /* Logout from server */
109 int		ftp_bye(struct ftp_con *);
110 
111 /* Set timeout value to n */
112 void	ftp_set_timeout_val(struct ftp_con *, int n);
113 
114 /* Issue to port command if active ftp else the pasv command */
115 int		ftp_port(struct ftp_con *);
116 
117 /* Make a ftp request req with arg arg */
118 int		ftp_req(struct ftp_con *, const char *fmt, ...)
119 	__attribute__ ((format (printf, 2, 3)));
120 
121 /* read data from server */
122 int		ftp_read_data(struct ftp_con *, char *buf, size_t size);
123 
124 /* set mode to passive if passive nonzero */
125 void	ftp_set_passive(struct ftp_con * c, int passive);
126 
127 /* specify where temp files should go */
128 void	ftp_set_tempdir(struct ftp_con * c, char *tempdir);
129 
130 #ifndef INET6
131 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
132 #define INET6
133 #endif
134 #endif
135 
136 #endif
137