FTP Server programmieren, Authentifikation...
-
Hallo!
Ich will einen kleinen FTP Server programmieren! Ich habe da ein Problem...wenn acceptet wird schicke ich "220 Connection accepted" alles schön und gut..dann bekomme ich vom Client USER Name...das kommt bei mir an und ich sage "331 Username ok need password" Doch dann macht der FTP Client nicht weiter! Woran kann das liegen?Danke
Kevin
-
wahrscheinlich an deinem prg aber die hellseher sind atm auf m jahrmarkt, die kommen erst in einer woche wieder.ich wuerde vorschlagen du postest code, geht schneller.
-
okay
is nur ne vorabversion zum connecten....
#include "windows.h" #include "winsock.h" #define WM_SOCKET_NOTIFY (WM_USER+1) static WORD WSAGetSelectE; //static bMay = TRUE; static struct sockaddr_in srv; static struct sockaddr_in sa; static struct sockaddr_in ca; BOOL bSize = FALSE; //static WSADATA wsa; static SOCKET s, sock; static int bytes; static int lca=sizeof(SOCKADDR); static char IP[100]; static char FILE[100]; static char received[1024]; static BOOL bDarf = FALSE; static char wantedpw[255]; static char gotuser[255]; void senden(const char *senden) { bytes=send(s,senden,strlen(senden),0); } void Userauswertung(char *user) { static int y = 0; char response[256]; for(int i = 5; user[i] != NULL; i++) { gotuser[y] = user[i]; y++; } gotuser[strlen(gotuser) - 2] = NULL; gotuser[strlen(gotuser) - 1] = NULL; wsprintf(response, "331 Username %s okay and whats the Password?\n", gotuser); } void Passauswertung(char *pw) { static int y = 0; for(int i = 4; pw[i] != NULL; i++) { wantedpw[y] = pw[i]; } MessageBox(0, pw, pw, 0); } void leeren() { for(int i = 0; i < 1024; i++) { received[i] = NULL; } } void Startup(HWND hWnd) { WSADATA WSAData; WSAStartup(MAKEWORD(2,0),&WSAData); sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); WSAAsyncSelect(sock,hWnd,WM_SOCKET_NOTIFY,FD_ACCEPT|FD_READ); } void hear(HWND hWnd) { sa.sin_family=AF_INET; sa.sin_port=htons(23); sa.sin_addr.S_un.S_addr=htonl(INADDR_ANY); bind(sock,(SOCKADDR*)&sa,sizeof(SOCKADDR_IN)); listen(sock,3); } LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); char szClassName[] = "Remoteit"; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nShowCmd) { HWND hWnd; MSG msg; WNDCLASS wc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.hIcon = LoadIcon(0, IDI_APPLICATION); wc.hCursor = LoadCursor(0, IDC_ARROW); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = szClassName; wc.lpszMenuName = 0; wc.style = CS_VREDRAW | CS_HREDRAW; RegisterClass(&wc); hWnd = CreateWindow(szClassName, "FarbFinder 1.0", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 250, 250, 0,0, hInstance, 0); ShowWindow(hWnd, nShowCmd); UpdateWindow(hWnd); while(GetMessage(&msg, 0,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } void emptyall() { for(int i = 0; i < 1024; i++) { IP[i] = NULL; FILE[i] = NULL; } } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hDC; static int i = 0; static int y = 0; static BOOL bDarf2; switch(message) { case WM_SOCKET_NOTIFY: WSAGetSelectE=WSAGETSELECTEVENT(lParam); //Das Ereignis abfangen für unsere switch-Schleife switch(WSAGetSelectE) { case FD_READ: bytes=recv(s,(char*)&received,sizeof(received),0); //dann lesen wir received[bytes]=NULL; if(received[0] == 'U' && received[1] == 'S' && received[2] == 'E' && received[3] == 'R') { Userauswertung(received); senden("331 User name okay, need password.\r\n"); } if(received[0] == 'P' && received[1] == 'A' && received[2] == 'S' && received[3] == 'S') { Passauswertung(received); } //auswerten(data); break; case FD_ACCEPT: s=accept(sock,(LPSOCKADDR)&ca,&lca); senden("220 Server ready v0.1\n\r\0"); break; } break; case WM_CREATE: Startup(hWnd); hear(hWnd); break; case WM_DESTROY: PostQuitMessage(0); return 0; break; } return DefWindowProc(hWnd, message, wParam, lParam); }
thxn
-
Weiß das wirklich niemand?