<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[FTP Client mit Winsock]]></title><description><![CDATA[<p>Hallo!</p>
<p>Habe mal versucht einen FTP Clienten mit Sockets zu programmieren.<br />
Mein Code sieht folgendermaßen aus:</p>
<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;winsock.h&gt;
#include &lt;winsock2.h&gt;
#include &lt;windows.h&gt;

using namespace std;

int gPort = 21;
int error = 0;
string msg = &quot;ftp&quot;;
string msp = &quot;mymail@thisurl.de&quot;;
string dir = &quot;dir&quot;;

int main(int)
{
       SOCKET lhSocket;
       SOCKADDR_IN lSockAddr;
       WSADATA wsaData;
       int lConnect;
       int lLength;
       char lData[]=&quot;SendData&quot;;
       if(WSAStartup(MAKEWORD(2,0),&amp;wsaData) != 0)
       {
            cout&lt;&lt;&quot;Socket Initialization Error. Program aborted\n&quot;;
            cin&gt;&gt;error;
            return 0;
        }
       lhSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
       if(lhSocket == INVALID_SOCKET)
       {
            cout&lt;&lt;&quot;Invalid Socket &quot;&lt;&lt;GetLastError()&lt;&lt;&quot;. Program Aborted\n&quot;&lt;&lt;endl;
            cin&gt;&gt;error;
        }
       memset(&amp;lSockAddr,0, sizeof(lSockAddr));
       lSockAddr.sin_family = AF_INET;
       lSockAddr.sin_port = htons(gPort);
       lSockAddr.sin_addr.s_addr = inet_addr(&quot;193.170.42.50&quot;);
       lConnect = connect(lhSocket,(SOCKADDR *)&amp;lSockAddr,sizeof(SOCKADDR_IN));
       if(lConnect != 0)
       {
             cout&lt;&lt;&quot;Connect Error. Program aborted\n&quot;;
             cin&gt;&gt;error;
             return 0;
        }

       send(lhSocket,msg.c_str(),strlen(msg.c_str()),0);
       Sleep(2000);
       send(lhSocket,msp.c_str(),strlen(msp.c_str()),0); 
       //hier sollte jetzt von dem Server eine Bestätigung des erfolgreichen
       //Logins kommen, daher müssen wir die Nachricht einlesen
      char temp[512];
      while (true)
       {

             int bytes = recv(lhSocket,temp,sizeof(temp)-1,0);
             temp[bytes] = '\0';
             cout&lt;&lt;temp;   
             send(lhSocket, dir.c_str(), strlen(dir.c_str()), 0);   
       }

       closesocket(lhSocket);
       return 0;

}
</code></pre>
<p>Führe ich den Code so aus, so scheint nichts zu passieren. Wenn ich aber die Zeile</p>
<pre><code>send(lhSocket, dir.c_str(), strlen(dir.c_str()), 0);
</code></pre>
<p>weglasse, bekomme ich folgende Meldung angezeigt (vom FTP Server)</p>
<blockquote>
<p>220 Serv-U FTP Server v6.2 for WinSock ready...</p>
</blockquote>
<p>Irgendwie scheint es mir, dass ich nicht eingeloggt bin bzw. keine Befehle absenden kann. Was mache ich falsch, bzw. wo liegt mein Fehler?</p>
<p>Hoffe, dass mir jemand helfen kann, da ich heute schon 4h probiert habe den Fehler zu finden aber nicht fündig wurde.</p>
<p>Danke schonmals für eure Hilfe<br />
lg thomas</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/158222/ftp-client-mit-winsock</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 02:18:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/158222.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 02 Sep 2006 22:37:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to FTP Client mit Winsock on Sat, 02 Sep 2006 22:37:05 GMT]]></title><description><![CDATA[<p>Hallo!</p>
<p>Habe mal versucht einen FTP Clienten mit Sockets zu programmieren.<br />
Mein Code sieht folgendermaßen aus:</p>
<pre><code>#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;winsock.h&gt;
#include &lt;winsock2.h&gt;
#include &lt;windows.h&gt;

using namespace std;

int gPort = 21;
int error = 0;
string msg = &quot;ftp&quot;;
string msp = &quot;mymail@thisurl.de&quot;;
string dir = &quot;dir&quot;;

int main(int)
{
       SOCKET lhSocket;
       SOCKADDR_IN lSockAddr;
       WSADATA wsaData;
       int lConnect;
       int lLength;
       char lData[]=&quot;SendData&quot;;
       if(WSAStartup(MAKEWORD(2,0),&amp;wsaData) != 0)
       {
            cout&lt;&lt;&quot;Socket Initialization Error. Program aborted\n&quot;;
            cin&gt;&gt;error;
            return 0;
        }
       lhSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
       if(lhSocket == INVALID_SOCKET)
       {
            cout&lt;&lt;&quot;Invalid Socket &quot;&lt;&lt;GetLastError()&lt;&lt;&quot;. Program Aborted\n&quot;&lt;&lt;endl;
            cin&gt;&gt;error;
        }
       memset(&amp;lSockAddr,0, sizeof(lSockAddr));
       lSockAddr.sin_family = AF_INET;
       lSockAddr.sin_port = htons(gPort);
       lSockAddr.sin_addr.s_addr = inet_addr(&quot;193.170.42.50&quot;);
       lConnect = connect(lhSocket,(SOCKADDR *)&amp;lSockAddr,sizeof(SOCKADDR_IN));
       if(lConnect != 0)
       {
             cout&lt;&lt;&quot;Connect Error. Program aborted\n&quot;;
             cin&gt;&gt;error;
             return 0;
        }

       send(lhSocket,msg.c_str(),strlen(msg.c_str()),0);
       Sleep(2000);
       send(lhSocket,msp.c_str(),strlen(msp.c_str()),0); 
       //hier sollte jetzt von dem Server eine Bestätigung des erfolgreichen
       //Logins kommen, daher müssen wir die Nachricht einlesen
      char temp[512];
      while (true)
       {

             int bytes = recv(lhSocket,temp,sizeof(temp)-1,0);
             temp[bytes] = '\0';
             cout&lt;&lt;temp;   
             send(lhSocket, dir.c_str(), strlen(dir.c_str()), 0);   
       }

       closesocket(lhSocket);
       return 0;

}
</code></pre>
<p>Führe ich den Code so aus, so scheint nichts zu passieren. Wenn ich aber die Zeile</p>
<pre><code>send(lhSocket, dir.c_str(), strlen(dir.c_str()), 0);
</code></pre>
<p>weglasse, bekomme ich folgende Meldung angezeigt (vom FTP Server)</p>
<blockquote>
<p>220 Serv-U FTP Server v6.2 for WinSock ready...</p>
</blockquote>
<p>Irgendwie scheint es mir, dass ich nicht eingeloggt bin bzw. keine Befehle absenden kann. Was mache ich falsch, bzw. wo liegt mein Fehler?</p>
<p>Hoffe, dass mir jemand helfen kann, da ich heute schon 4h probiert habe den Fehler zu finden aber nicht fündig wurde.</p>
<p>Danke schonmals für eure Hilfe<br />
lg thomas</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1129931</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1129931</guid><dc:creator><![CDATA[ftpuser]]></dc:creator><pubDate>Sat, 02 Sep 2006 22:37:05 GMT</pubDate></item><item><title><![CDATA[Reply to FTP Client mit Winsock on Sat, 02 Sep 2006 22:49:39 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile.php?mode=viewprofile&amp;u=10455" rel="nofollow">evilissimo</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=15" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum.php?f=4" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39405" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1129932</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1129932</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Sat, 02 Sep 2006 22:49:39 GMT</pubDate></item><item><title><![CDATA[Reply to FTP Client mit Winsock on Sat, 02 Sep 2006 23:48:14 GMT]]></title><description><![CDATA[<p>nach dem connect() schickt der FTP-Server dir erstmal den Banner (&quot;220 Serv-U FTP Se...&quot;), du solltest die Antwort vom FTP-Server einlesen und ihm nicht einfach wild irgendwelche Nachrichten schicken <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";D"
      alt="😉"
    /></p>
<p>Und aufgepasst bei recv()!!!<br />
recv() füllt NICHT zwingend den kompletten Buffer!<br />
Du solltest recv() aufrufen bis du den EndOfLine-Marker bekommen hast, sonst kann es dir passieren dass du nur die halbe Antwort eingelesen hast und den Server schon wieder was schickst!</p>
<p>Ansonsten noch ein Tipp (hier wird einiges bezügl. des ftp-protokolls ganz gut erklärt):<br />
<a href="http://cr.yp.to/ftp.html" rel="nofollow">http://cr.yp.to/ftp.html</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1129955</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1129955</guid><dc:creator><![CDATA[geeky]]></dc:creator><pubDate>Sat, 02 Sep 2006 23:48:14 GMT</pubDate></item></channel></rss>