<?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[Mehrere Dateien übertragen]]></title><description><![CDATA[<p>Hallo Leute!<br />
Ich möchte mehrere Dateien aus einem Verzeichnis zu einem anderen Computer übertragen. Leider läuft im Code nicht alles synchron. Hat einer eine Idee wie ich das vielleicht noch lösen könnte oder Verbesserungsvrschläge für den Code??<br />
Client:</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#include &lt;stdio.h&gt;
#include &lt;fstream.h&gt;
#pragma hdrstop

#include &quot;Unit1.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
TMemoryStream *memsend=new TMemoryStream();
int img_size=0;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
   CopyStop=false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
ClientSocket1-&gt;Open();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ClientSocket1Error(TObject *Sender,
      TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &amp;ErrorCode)
{
  // analyse ErrorEvent
  String Msg = &quot;Unspecified ClientSocket error.&quot;;
  switch(ErrorEvent)
  {
    case eeGeneral :
      Msg = &quot;The socket received an error message that does not fit into any category.&quot;;
    case eeSend :
      Msg = &quot;An error occurred when trying to write to the socket connection.&quot;;
      break;
    case eeReceive :
      Msg =  &quot;An error occurred when trying to read from the socket connection.&quot;;
      break;
    case eeConnect :
      Msg = &quot;A connection request that was already accepted could not be completed.&quot;;
      break;
    case eeDisconnect :
      Msg = &quot;An error occurred when trying to close a connection.&quot;;
      break;
    case eeAccept :
      Msg = &quot;A problem occurred when trying to accept a client connection request.&quot;;
  }
  Application-&gt;MessageBox(Msg.c_str(), &quot;ClientSocket Error&quot;, MB_OK | MB_ICONSTOP);

  // prevent exception
  ErrorCode = 0;
}
//---------------------------------------------------------------------------
void TForm1::BackupDirectory (char *qpath)
{
int erg=0;
struct TSearchRec SR;
char qpath2 [500];

strcpy (qpath2,qpath);
if (qpath2[strlen (qpath2)-1]=='\\')
strcat (qpath2,&quot;*.*&quot;);

FindFirst(qpath2,faAnyFile,SR);

strcpy (qpath2,qpath);

     while (erg==0)
     {
       Application-&gt;ProcessMessages();
        if (CopyStop==true) return;

        strcpy (qpath2,qpath);

        if (qpath2[strlen (qpath2)-1]=='\\')
                   strcat (qpath2,SR.Name.c_str());

        if (SR.Name!=&quot;.&quot;&amp;&amp;SR.Name!=&quot;..&quot;&amp;&amp;(SR.Attr&amp;faDirectory)&lt;=0)
        {
            ClientSocket1-&gt;Socket-&gt;SendText (SR.Name);
            senden (qpath2, SR.Name);
        }

          erg=FindNext (SR);

     }
}

//----------------------------------------------------------

void TForm1::senden (char *qpath, AnsiString FileName)
{
char *path5=&quot;C:\\sordner\\&quot;;
char path6 [500];
strcpy (path6,path5);
strcat (path6,FileName.c_str());
AnsiString status;
char string [5];

while (status!=&quot;_get&quot;)
{
   status=ClientSocket1-&gt;Socket-&gt;ReceiveText();
   Application-&gt;ProcessMessages();
   if (CopyStop==true) status=&quot;_get&quot;;
}

Memo1-&gt;Lines-&gt;Add (FileName);

TFileStream* datei= new TFileStream (qpath,fmOpenRead);
   memsend-&gt;LoadFromStream (datei);
  img_size = memsend-&gt;Size;

  memsend-&gt;Seek(0, soFromBeginning);
  memsend-&gt;Read(string, 4);
  memsend-&gt;Seek(0, soFromEnd);
  memsend-&gt;Write(string, 4);

  memsend-&gt;Seek(0, soFromBeginning);
  memsend-&gt;Write(&amp;img_size, 4);

  img_size = 0;

  memsend-&gt;Seek(0, soFromBeginning);
  ClientSocket1-&gt;Socket-&gt;SendBuf(memsend-&gt;Memory,memsend-&gt;Size);
  delete datei;
  memsend-&gt;Clear();
}

//-----------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
CopyStop=true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::hh(TObject *Sender, TCustomWinSocket *Socket)
{
  BackupDirectory (&quot;C:\\n\\&quot;);
}
//---------------------------------------------------------------------------
</code></pre>
<p>Server:</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#include &lt;jpeg.hpp&gt;
#pragma hdrstop

#include &quot;Unit1.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
TMemoryStream *mem=new TMemoryStream(); 
int img_size=0; 

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
Stream_Exist=false;
i=0;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::onread(TObject *Sender, TCustomWinSocket *Socket)
{
char path [200],path2 [200];
strcpy (path2,&quot;C:\\sicherung\\&quot;);
img_size=0;

 if (Stream_Exist==true)
 {
 int bufsize = Socket-&gt;ReceiveLength();
  BYTE *Buffer = new BYTE[bufsize];

  mem-&gt;Seek(0, soFromEnd);
  Socket-&gt;ReceiveBuf(Buffer, bufsize);
  mem-&gt;Write(Buffer, bufsize);
  delete [] Buffer;

     if (img_size == 0)
     {

          mem-&gt;Seek(0, soFromBeginning);
          mem-&gt;Read(&amp;img_size, 4);
     }

    if (mem-&gt;Size == (img_size + 4))
    {

     char ch[5];
     mem-&gt;Seek(-4, soFromEnd);
     mem-&gt;Read(ch, 4);
     mem-&gt;Seek(0, soFromBeginning);
     mem-&gt;Write(ch, 4);

           mem-&gt;Size -= 4;

          mem-&gt;Seek(0, soFromBeginning);
          datei-&gt;CopyFrom (mem,mem-&gt;Size);
          mem-&gt;Clear();
          delete datei;
          Stream_Exist=false;

    }

 }

  if (Stream_Exist==false)
  {

   AnsiString FileName;
    FileName=Socket-&gt;ReceiveText();

   strcpy (path,path2);
   strcat (path,FileName.c_str ());
   Memo1-&gt;Lines-&gt;Add (FileName);
   Label1-&gt;Caption=i;
   ServerSocket1-&gt;Socket-&gt;Connections[0]-&gt;SendText (&quot;_get&quot;);

   datei=new TFileStream (path,fmCreate);

  Stream_Exist=true;
  i++;
  img_size=0;
  }

}
//---------------------------------------------------------------------------

void __fastcall TForm1::sadsad(TObject *Sender, TCustomWinSocket *Socket,
      TErrorEvent ErrorEvent, int &amp;ErrorCode)
{
  // analyse ErrorEvent 
  String Msg = &quot;Unspecified ClientSocket error.&quot;; 
  switch(ErrorEvent) 
  { 
    case eeGeneral : 
      Msg = &quot;The socket received an error message that does not fit into any category.&quot;; 
    case eeSend : 
      Msg = &quot;An error occurred when trying to write to the socket connection.&quot;; 
      break; 
    case eeReceive : 
      Msg =  &quot;An error occurred when trying to read from the socket connection.&quot;; 
      break; 
    case eeConnect : 
      Msg = &quot;A connection request that was already accepted could not be completed.&quot;; 
      break; 
    case eeDisconnect : 
      Msg = &quot;An error occurred when trying to close a connection.&quot;; 
      break; 
    case eeAccept : 
      Msg = &quot;A problem occurred when trying to accept a client connection request.&quot;; 
  } 
  Application-&gt;MessageBox(Msg.c_str(), &quot;ClientSocket Error&quot;, MB_OK | MB_ICONSTOP); 

  // prevent exception 
  ErrorCode = 0;
}
//---------------------------------------------------------------------------
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/105278/mehrere-dateien-übertragen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Jul 2026 13:20:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/105278.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 Mar 2005 20:12:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Mehrere Dateien übertragen on Mon, 28 Mar 2005 20:12:07 GMT]]></title><description><![CDATA[<p>Hallo Leute!<br />
Ich möchte mehrere Dateien aus einem Verzeichnis zu einem anderen Computer übertragen. Leider läuft im Code nicht alles synchron. Hat einer eine Idee wie ich das vielleicht noch lösen könnte oder Verbesserungsvrschläge für den Code??<br />
Client:</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#include &lt;stdio.h&gt;
#include &lt;fstream.h&gt;
#pragma hdrstop

#include &quot;Unit1.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
TMemoryStream *memsend=new TMemoryStream();
int img_size=0;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
   CopyStop=false;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
ClientSocket1-&gt;Open();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ClientSocket1Error(TObject *Sender,
      TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &amp;ErrorCode)
{
  // analyse ErrorEvent
  String Msg = &quot;Unspecified ClientSocket error.&quot;;
  switch(ErrorEvent)
  {
    case eeGeneral :
      Msg = &quot;The socket received an error message that does not fit into any category.&quot;;
    case eeSend :
      Msg = &quot;An error occurred when trying to write to the socket connection.&quot;;
      break;
    case eeReceive :
      Msg =  &quot;An error occurred when trying to read from the socket connection.&quot;;
      break;
    case eeConnect :
      Msg = &quot;A connection request that was already accepted could not be completed.&quot;;
      break;
    case eeDisconnect :
      Msg = &quot;An error occurred when trying to close a connection.&quot;;
      break;
    case eeAccept :
      Msg = &quot;A problem occurred when trying to accept a client connection request.&quot;;
  }
  Application-&gt;MessageBox(Msg.c_str(), &quot;ClientSocket Error&quot;, MB_OK | MB_ICONSTOP);

  // prevent exception
  ErrorCode = 0;
}
//---------------------------------------------------------------------------
void TForm1::BackupDirectory (char *qpath)
{
int erg=0;
struct TSearchRec SR;
char qpath2 [500];

strcpy (qpath2,qpath);
if (qpath2[strlen (qpath2)-1]=='\\')
strcat (qpath2,&quot;*.*&quot;);

FindFirst(qpath2,faAnyFile,SR);

strcpy (qpath2,qpath);

     while (erg==0)
     {
       Application-&gt;ProcessMessages();
        if (CopyStop==true) return;

        strcpy (qpath2,qpath);

        if (qpath2[strlen (qpath2)-1]=='\\')
                   strcat (qpath2,SR.Name.c_str());

        if (SR.Name!=&quot;.&quot;&amp;&amp;SR.Name!=&quot;..&quot;&amp;&amp;(SR.Attr&amp;faDirectory)&lt;=0)
        {
            ClientSocket1-&gt;Socket-&gt;SendText (SR.Name);
            senden (qpath2, SR.Name);
        }

          erg=FindNext (SR);

     }
}

//----------------------------------------------------------

void TForm1::senden (char *qpath, AnsiString FileName)
{
char *path5=&quot;C:\\sordner\\&quot;;
char path6 [500];
strcpy (path6,path5);
strcat (path6,FileName.c_str());
AnsiString status;
char string [5];

while (status!=&quot;_get&quot;)
{
   status=ClientSocket1-&gt;Socket-&gt;ReceiveText();
   Application-&gt;ProcessMessages();
   if (CopyStop==true) status=&quot;_get&quot;;
}

Memo1-&gt;Lines-&gt;Add (FileName);

TFileStream* datei= new TFileStream (qpath,fmOpenRead);
   memsend-&gt;LoadFromStream (datei);
  img_size = memsend-&gt;Size;

  memsend-&gt;Seek(0, soFromBeginning);
  memsend-&gt;Read(string, 4);
  memsend-&gt;Seek(0, soFromEnd);
  memsend-&gt;Write(string, 4);

  memsend-&gt;Seek(0, soFromBeginning);
  memsend-&gt;Write(&amp;img_size, 4);

  img_size = 0;

  memsend-&gt;Seek(0, soFromBeginning);
  ClientSocket1-&gt;Socket-&gt;SendBuf(memsend-&gt;Memory,memsend-&gt;Size);
  delete datei;
  memsend-&gt;Clear();
}

//-----------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
CopyStop=true;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::hh(TObject *Sender, TCustomWinSocket *Socket)
{
  BackupDirectory (&quot;C:\\n\\&quot;);
}
//---------------------------------------------------------------------------
</code></pre>
<p>Server:</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#include &lt;jpeg.hpp&gt;
#pragma hdrstop

#include &quot;Unit1.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
TMemoryStream *mem=new TMemoryStream(); 
int img_size=0; 

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
Stream_Exist=false;
i=0;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::onread(TObject *Sender, TCustomWinSocket *Socket)
{
char path [200],path2 [200];
strcpy (path2,&quot;C:\\sicherung\\&quot;);
img_size=0;

 if (Stream_Exist==true)
 {
 int bufsize = Socket-&gt;ReceiveLength();
  BYTE *Buffer = new BYTE[bufsize];

  mem-&gt;Seek(0, soFromEnd);
  Socket-&gt;ReceiveBuf(Buffer, bufsize);
  mem-&gt;Write(Buffer, bufsize);
  delete [] Buffer;

     if (img_size == 0)
     {

          mem-&gt;Seek(0, soFromBeginning);
          mem-&gt;Read(&amp;img_size, 4);
     }

    if (mem-&gt;Size == (img_size + 4))
    {

     char ch[5];
     mem-&gt;Seek(-4, soFromEnd);
     mem-&gt;Read(ch, 4);
     mem-&gt;Seek(0, soFromBeginning);
     mem-&gt;Write(ch, 4);

           mem-&gt;Size -= 4;

          mem-&gt;Seek(0, soFromBeginning);
          datei-&gt;CopyFrom (mem,mem-&gt;Size);
          mem-&gt;Clear();
          delete datei;
          Stream_Exist=false;

    }

 }

  if (Stream_Exist==false)
  {

   AnsiString FileName;
    FileName=Socket-&gt;ReceiveText();

   strcpy (path,path2);
   strcat (path,FileName.c_str ());
   Memo1-&gt;Lines-&gt;Add (FileName);
   Label1-&gt;Caption=i;
   ServerSocket1-&gt;Socket-&gt;Connections[0]-&gt;SendText (&quot;_get&quot;);

   datei=new TFileStream (path,fmCreate);

  Stream_Exist=true;
  i++;
  img_size=0;
  }

}
//---------------------------------------------------------------------------

void __fastcall TForm1::sadsad(TObject *Sender, TCustomWinSocket *Socket,
      TErrorEvent ErrorEvent, int &amp;ErrorCode)
{
  // analyse ErrorEvent 
  String Msg = &quot;Unspecified ClientSocket error.&quot;; 
  switch(ErrorEvent) 
  { 
    case eeGeneral : 
      Msg = &quot;The socket received an error message that does not fit into any category.&quot;; 
    case eeSend : 
      Msg = &quot;An error occurred when trying to write to the socket connection.&quot;; 
      break; 
    case eeReceive : 
      Msg =  &quot;An error occurred when trying to read from the socket connection.&quot;; 
      break; 
    case eeConnect : 
      Msg = &quot;A connection request that was already accepted could not be completed.&quot;; 
      break; 
    case eeDisconnect : 
      Msg = &quot;An error occurred when trying to close a connection.&quot;; 
      break; 
    case eeAccept : 
      Msg = &quot;A problem occurred when trying to accept a client connection request.&quot;; 
  } 
  Application-&gt;MessageBox(Msg.c_str(), &quot;ClientSocket Error&quot;, MB_OK | MB_ICONSTOP); 

  // prevent exception 
  ErrorCode = 0;
}
//---------------------------------------------------------------------------
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/754445</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/754445</guid><dc:creator><![CDATA[roenemeyer]]></dc:creator><pubDate>Mon, 28 Mar 2005 20:12:07 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrere Dateien übertragen on Tue, 29 Mar 2005 18:42:30 GMT]]></title><description><![CDATA[<p>Naja. Vielleicht war mein Beitrag auch ein bischen dumm gestellt. Der Code wie ich ihn da habe funktioniert so nicht. Es wird nur eine Datei übertragen. Dann stürzt das Programm ab. Ich denke so wie ich das in dem Code realisiert habe kann man das nicht machen. Könnte mir vielleicht von euch jemand sagen wie er mehrere Dateien übertragen würde? Eine Datei bekomme ich hin aber mehrere nicht....<br />
Ich wäre um viele Antworten dankbar</p>
]]></description><link>https://www.c-plusplus.net/forum/post/755207</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/755207</guid><dc:creator><![CDATA[roenemeyer]]></dc:creator><pubDate>Tue, 29 Mar 2005 18:42:30 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrere Dateien übertragen on Tue, 29 Mar 2005 21:52:04 GMT]]></title><description><![CDATA[<p>gleichzeitig oder nacheinander (alla ICQ,MSN)?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/755343</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/755343</guid><dc:creator><![CDATA[DJ BlackEagle]]></dc:creator><pubDate>Tue, 29 Mar 2005 21:52:04 GMT</pubDate></item><item><title><![CDATA[Reply to Mehrere Dateien übertragen on Tue, 29 Mar 2005 22:22:18 GMT]]></title><description><![CDATA[<p>Die Dateien sollen nacheinander übertragen werden. Ich habe das jetzt endlich nach vielem hin und her hinbekommen. Wie würdest du das den machen DJBlackEagle? Vielleicht ist deine Methode ja eleganter.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/755349</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/755349</guid><dc:creator><![CDATA[roenemeyer]]></dc:creator><pubDate>Tue, 29 Mar 2005 22:22:18 GMT</pubDate></item></channel></rss>