Problem Reciving data in ftp using winsock [modified]
-
Hi, Im pretty new to C++.. been messing with the standard library for a while.. but im in need of some help here.. i apologise i dont really have decent code to show.. as i said im new... Anyway.. the problem is im getting some strange imput from the command line console some after the accepting socket... heres what i get... C:\>winsock Listening on Socket USER test q▲∟¼q↔¼q^↔¼qzv½qPëV PASS test qi ¼q2è½q►=½q╡↔¼qµ@½qUSER test q▲∟¼q↔¼q^↔¼qzv½qPëV Listening on Socket Yeah.. my computer beeps and everything.. some strange mating call of FTP i presume... basically i was wondering what that is.. and how to recieve data in only regular text format after sending data... so i can process the login and other ftp commands... heres what i get in the client so far for this code... [R] Connecting to 127.0.0.1 -> IP=127.0.0.1 PORT=21 [R] Connected to 127.0.0.1 [R] 220 Welcome to my Custom FTP [R] USER test [R] 331 Password Required [R] PASS (hidden) [R] 230 Welcome to my Custom FTP. [R] SYST [R] QUIT please have a look at the code... im using devc++ and it does compile ok... without further wait.. heres what ive got so far... #include #include #include using namespace std; int accept(SOCKET AcceptSocket, SOCKET ListenSocket); int main() { int sk; WSAData wsaData; WORD wVersionRequested; wVersionRequested=MAKEWORD(2, 0); WSAStartup( wVersionRequested, &wsaData ); sockaddr_in service; service.sin_family = AF_INET; service.sin_addr.s_addr = inet_addr("127.0.0.1"); service.sin_port = htons(21); int test; while(1){ SOCKET ListenSocket; ListenSocket = socket(AF_INET, SOCK_STREAM, 0); if (bind( ListenSocket, (SOCKADDR*) &service, sizeof(service)) == SOCKET_ERROR) { cout << "bind() failed.\n"; closesocket(ListenSocket); return 1; } cout << "Listening on Socket\n"; SOCKET AcceptSocket; sk=listen( ListenSocket, 10 ); AcceptSocket = accept( ListenSocket, NULL, NULL ); test=accept(AcceptSocket, ListenSocket); #ifdef WIN32 Sleep( 5000 ); #endif if(test==2){break;} } WSACleanup(); return 0; } int accept (SOCKET AcceptSocket, SOCKET ListenSocket) { int bytesSent; int bytesRecv; int test; char sendbuf[1024] = "220 Welcome to my Custom FTP\n"; char* recvbuf = ""; char user[32]; char pass[32]; bytesSent=send( AcceptSocket, sendbuf, strlen(sendbuf), 0 );