File: ftpclient.h

package info (click to toggle)
ftp.app 0.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 664 kB
  • sloc: objc: 2,955; makefile: 11
file content (115 lines) | stat: -rw-r--r-- 3,186 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 Project: FTP

 Copyright (C) 2005-2015 Riccardo Mottola

 Author: Riccardo Mottola

 Created: 2005-03-30

 FTP client class

 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

 */

#include <string.h> /* for bcopy or memcpy */

#ifdef _WIN32
#include <windows.h>
#include <winsock.h>
#define BCOPY(SRC, DST, LEN) memcpy(DST, SRC, LEN)
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define BCOPY(SRC, DST, LEN) bcopy(SRC, DST, LEN)
#endif /* WIN32 */

#include <stdio.h>

#import <Foundation/Foundation.h>
#import "client.h"
#import "localclient.h"
#import "fileElement.h"


#define MAX_SOCK_BUFF 1024

#define MAX_DIR_RECURSION 5

#define ERR_COULDNT_RESOLVE -1
#define ERR_SOCKET_FAIL -2
#define ERR_CONNECT_FAIL -3
#define ERR_GESOCKNAME_FAIL -4
#define ERR_READ_FAIL -5

/** connection types: PASV or PORT */
typedef enum { defaultMode, portMode, passiveMode } connectionModes;

/** private structure to use a socket like it was a file stream */
typedef struct
{
    int socket;
    int position;
    int len;
    char buffer[MAX_SOCK_BUFF];
} streamStruct;

@interface FtpClient : Client
{
    int                 userDataPort;
    int                 serverDataPort;
    int                 dataSocket;
    int                 controlSocket;
    int                 localSocket;
    streamStruct        dataStream;
    streamStruct        ctrlStream;
    struct sockaddr_in  remoteSockName;
    struct sockaddr_in  localSockName;
    struct sockaddr_in  dataSockName;
    BOOL                usesPassive;
    BOOL                usesPorts;
    @protected BOOL     connected;
}

- (id)initWithController:(id)cont :(connectionModes)cMode;
- (void)setPortDefault;
- (void)setPortPort;
- (void)setPortPassive;

- (void)logIt:(NSString *)str;

/** reads a reply from the control socket */
- (int)readReply :(NSMutableArray **)result;

- (int)writeLine:(NSString *)line;
- (int)writeLine:(NSString *)line byLoggingIt:(BOOL)doLog;
- (oneway void)retrieveFile:(FileElement *)file to:(LocalClient *)localClient;
- (BOOL)retrieveFile:(FileElement *)file to:(LocalClient *)localClient beingAt:(int)depth;
- (oneway void)storeFile:(FileElement *)file from:(LocalClient *)localClient;
- (BOOL)storeFile:(FileElement *)file from:(LocalClient *)localClient beingAt:(int)depth;

- (int)connect:(int)port :(char *)server;
- (void)disconnect;
- (int)authenticate:(NSString *)user :(NSString *)pass;
- (int)initDataConn;
- (int)initDataStream;
- (int)closeDataConn;
- (void)closeDataStream;

@end