www.pudn.com > ftpd.rar > ftpc.c
/* Talk (TCP) example for DSock, copyright (C) 2002 by DM&P. It's show you how to use sockets to connect to Internet. It's also provide a Windows version written by WinSock. */ #include "..\dsock.h" #include#include #define FTP_PORT 21 char szBuf[32]; BOOL FtpClient(SOCKET s, char *szServer); int main(int nArgCnt, char **pszArg) { DWORD dwIp; SOCKET s; printf("\nDM&P DSock Talk-TCP Example Program\n\n"); /* Open DSock library */ if(DSock_Open() == FALSE) { printf("Unable to initialize socket library\n"); return 1; } /* Load network setup from config file */ DSock_LoadConfigFile("dsock.cfg"); /* Show my IP */ dwIp = DSock_GetHostIp(); inet_ntoa(szBuf, dwIp); printf("My IP : %s\n", szBuf); s = SocketCreate(TCP_SOCKET); if(s == INVALID_SOCKET) { printf("SocketCreate() error\n"); DSock_Close(); return 1; } if(nArgCnt>1) FtpClient(s, pszArg[1]); else printf("Please Input server IP and Port\n"); SocketClose(s); SocketDestory(s); /* Close DSock library */ DSock_Close(); return 0; } BOOL FtpClient(SOCKET s, char *szServer) { char szBuf[1024]; printf("Talk client mode, connecting to server...\n"); /* Connect to server */ if(SocketConnect(s, inet_addr(szServer), FTP_PORT) == FALSE) { printf("SocketConnect() error\n"); return FALSE; } if(SocketDataReady(s)) { SocketGetString(s, szBuf, 1024); printf("%s\n", szBuf); printf("Connected to %s:%d\n", szServer, FTP_PORT); } else return FALSE; //SocketPutString(s, "%s\n", "user user"); SocketPutString(s, "%s\n", "pass dmpr"); if(SocketDataReady(s)) { SocketGetString(s, szBuf, 1024); printf("%s\n", szBuf); } else return FALSE; while(TRUE) { /* Check key press and send it out */ char c=0; if(kbhit()) { c = getch(); switch( c) { case 27: printf("\nProgram terminated\n"); break; case 'l': case 'L': Socket s2; SocketPutString(s, "%s\n", "list"); s2 = SocketCreate(TCP_SOCKET); SocketConnect(s2, inet_addr(szServer), FTP_PORT); while(SocketGetString(s2,szBuf,1024)) printf("%s\n", szBuf); SocketClose(s2); SocketDestory(s2); printf("Send directory end\n"); break; case 'S': case 's': break; case 'd': case 'D': break; } } if(c==27) { printf("\nProgram terminated\n"); break; } } return TRUE; }