Note that there are some explanatory texts on larger screens.

plurals
  1. POWinsock problems sending data C++
    primarykey
    data
    text
    <p>I'm trying to code a simple FTP client with Winsock. </p> <p>I have the following code:</p> <pre><code>using namespace std; #include &lt;iostream&gt; #include &lt;cstring&gt; #include &lt;cstdio&gt; #include &lt;winsock.h&gt; #include &lt;windows.h&gt; int main() { const int MAX_TRIES = 10; char * host = "localhost"; int port = 21; char * userName = "b8_8780454"; char * pass = "test"; char * testFileSource = "C:\\Windows\\notepad.exe"; WSADATA WSAData; SOCKADDR_IN server; SOCKET sock; WSAStartup(MAKEWORD(2,2), &amp;WSAData); sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock == INVALID_SOCKET) { cout&lt;&lt;"fail"; return -1; } server.sin_family = PF_INET; server.sin_port = htons(port); server.sin_addr = *((struct in_addr *)gethostbyname(host)-&gt;h_addr); memset(server.sin_zero,0,8); int errorCode = connect(sock, (LPSOCKADDR)&amp;server, sizeof(struct sockaddr)); int tries = 0; while (errorCode == SOCKET_ERROR) { if (tries &gt;= MAX_TRIES) { cout&lt;&lt;"fail 2"; return -1; } errorCode = connect(sock, (LPSOCKADDR)&amp;server, sizeof(struct sockaddr)); tries++; } char serverMsg[2048]; Sleep(1000); cout&lt;&lt;"Waiting for server response..."&lt;&lt;endl; int r = recv(sock,serverMsg,2048,0); serverMsg[r] = '\0'; cout&lt;&lt;endl&lt;&lt;endl&lt;&lt;"Server said: "&lt;&lt;endl&lt;&lt;serverMsg&lt;&lt;endl&lt;&lt;endl; char userB[1024] = "USER "; strcat(userB,userName); cout&lt;&lt;"Sending... "&lt;&lt;userB&lt;&lt;endl; cout&lt;&lt;"sended: "&lt;&lt;send(sock, userB, strlen(userB), 0)&lt;&lt;" bytes"&lt;&lt;endl; Sleep(1000); cout&lt;&lt;"Waiting for server response..."&lt;&lt;endl; serverMsg[0] = '\0'; recv(sock,serverMsg,2048,0); // &lt;-- program keeps lock here cout&lt;&lt;endl&lt;&lt;endl&lt;&lt;"Server said: "&lt;&lt;endl&lt;&lt;serverMsg&lt;&lt;endl&lt;&lt;endl; getchar(); return 0; } </code></pre> <p>I think the send is not working properly, nevertheless it is returning >0 but on the server side i can't see this client sending any data. I think i maybe a problem with the conection setup, but i have been checking some sites and I am not able to catch the error</p> <p>This is what the program prints:</p> <p>Waiting for server response...</p> <pre><code>Server said: 220-FileZilla Server version 0.9.31 beta 220-written by Tim Kosse (Tim.Kosse@gmx.de) 220 Please visit http://sourceforge.net/projects/filezilla/ Sending... USER b8_8780454 sended: 15 bytes Waiting for server response... Server said: 421 Login time exceeded. Closing control connection. by Tim Kosse (Tim.Kosse@gmx.de) 220 Please visit http://sourceforge.net/projects/filezilla/ </code></pre> <p>In my FTP server I can't see this client sending any data to the server. Any clue?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload