home *** CD-ROM | disk | FTP | other *** search
- #include "FtpLibrary.h"
-
- STATUS FtpConnect(FTP **con,char * hostname)
- {
- struct sockaddr_in unit;
- register struct hostent *host;
- register struct servent *service;
- register int sock;
- String S1;
- STATUS x;
-
- *con = ( FTP * ) malloc ( sizeof (FTP));
-
- if ((host=gethostbyname(hostname))==0)
- return EXIT((*con),QUIT);
- if ((service=(struct servent *) getservbyname("ftp","tcp"))==0)
- return EXIT((*con),QUIT);
-
- unit.sin_family = host -> h_addrtype;
-
- bcopy(host-> h_addr_list[0],&unit.sin_addr,host->h_length);
- if ( ( sock = socket ( unit.sin_family , SOCK_STREAM , 0)) < 0)
- return EXIT((*con),QUIT);
-
- unit.sin_port = service -> s_port;
-
- while ( connect ( sock , &unit , sizeof unit ) < 0 )
- {
- host -> h_addr_list ++;
- bcopy(host -> h_addr_list[0],&unit,host->h_length);
- close(sock);
- if ( ( sock = socket ( unit.sin_family , SOCK_STREAM , 0)) < 0)
- return EXIT((*con),QUIT);
- }
-
- (*con) -> sock = sock;
- (*con) -> mode = 'A';
- (*con) -> data = 0;
- (*con) -> func = NULL;
- (*con) -> debug = NULL;
-
- if ( (x=FtpGetMessage(*con,S1)) == QUIT )
- return EXIT((*con),QUIT);
- if ( ! FtpGood(x,120,220,EOF))
- {
- close(sock);
- return EXIT((*con),-x);
- }
- return EXIT((*con),x);
- }
-