| 65 |
int ftp_initialize( LIBOFTP *ftp ) |
int ftp_initialize( LIBOFTP *ftp ) |
| 66 |
{ |
{ |
| 67 |
memset( ftp, 0, sizeof( LIBOFTP ) ); |
memset( ftp, 0, sizeof( LIBOFTP ) ); |
| 68 |
|
ftp->socket = -1; |
| 69 |
ftp->timeout_sec = 10; /* default timeout */ |
ftp->timeout_sec = 10; /* default timeout */ |
| 70 |
|
|
| 71 |
return LIBOFTP_NOERROR; |
return LIBOFTP_NOERROR; |
| 88 |
struct hostent *p_hostent; |
struct hostent *p_hostent; |
| 89 |
int res; |
int res; |
| 90 |
|
|
| 91 |
|
if( ftp->socket >= 0 ) return LIBOFTP_ERROR; |
| 92 |
if( port == 0 ) port = 21; |
if( port == 0 ) port = 21; |
| 93 |
|
|
| 94 |
/* |
/* |
| 111 |
if( ftp->socket < 0 ) { |
if( ftp->socket < 0 ) { |
| 112 |
DEBUGPRINT1( "can't create socket. %s\n", strerror(errno) ); |
DEBUGPRINT1( "can't create socket. %s\n", strerror(errno) ); |
| 113 |
copy_strerror(); |
copy_strerror(); |
| 114 |
ftp->socket = 0; |
ftp->socket = -1; |
| 115 |
return LIBOFTP_ERROR_OS; |
return LIBOFTP_ERROR_OS; |
| 116 |
} |
} |
| 117 |
|
|
| 119 |
DEBUGPRINT1( "can't connect socket. %s\n", strerror(errno) ); |
DEBUGPRINT1( "can't connect socket. %s\n", strerror(errno) ); |
| 120 |
copy_strerror(); |
copy_strerror(); |
| 121 |
close( ftp->socket ); |
close( ftp->socket ); |
| 122 |
ftp->socket = 0; |
ftp->socket = -1; |
| 123 |
return LIBOFTP_ERROR_OS; |
return LIBOFTP_ERROR_OS; |
| 124 |
} |
} |
| 125 |
|
|
| 126 |
res = ftp_timeout( ftp, ftp->timeout_sec ); |
res = ftp_timeout( ftp, ftp->timeout_sec ); |
| 127 |
if( res < 0 ) { |
if( res < 0 ) { |
| 128 |
close( ftp->socket ); |
close( ftp->socket ); |
| 129 |
ftp->socket = 0; |
ftp->socket = -1; |
| 130 |
return res; |
return res; |
| 131 |
} |
} |
| 132 |
|
|
| 137 |
if( res != 220 ) { /* 220: Service ready for new user. */ |
if( res != 220 ) { /* 220: Service ready for new user. */ |
| 138 |
DEBUGPRINT1( "Illegal response. %d\n", res ); |
DEBUGPRINT1( "Illegal response. %d\n", res ); |
| 139 |
close( ftp->socket ); |
close( ftp->socket ); |
| 140 |
ftp->socket = 0; |
ftp->socket = -1; |
| 141 |
return res < 0? res: LIBOFTP_ERROR_PROTOCOL; |
return res < 0? res: LIBOFTP_ERROR_PROTOCOL; |
| 142 |
} |
} |
| 143 |
|
|