Socket.Receive Issue - not returning all data

T

TacoGod

I am trying to retrieve a file list from a ftp. I got this code from
the microsoft website:

Do While (True)
m_aBuffer.Clear(m_aBuffer, 0, m_aBuffer.Length)
bytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length,
SocketFlags.None)
m_sMes += ASCII.GetString(m_aBuffer, 0, bytes)
Console.WriteLine(m_sMes)
If (bytes < m_aBuffer.Length) Then
Exit Do
End If
Loop

This code works fine if I put a break after the Socket.Receive. The
number of bytes it should return is 380. If I put a break after the
receive all 380 get transferred. If I don't put a break in the code,
the app seems to run to fast and only returns 20 bytes.

Should the code stop to receive everything before continuing? Am I
doing something wrong here?

Thanks
 
D

Dick Grier

Hi,
Should the code stop to receive everything before continuing? Am I
doing something wrong here?
<<

All your code will do is to return whatever data is available at any one
instant in time. If you know how much data you should receive, simply wait
until it is all there (this may take a number of cycles through a loop). If
you don't know how much data should be retrieved, you should set up a thread
to retrieve data and to notify you (I use an event) as data are retrieved --
you then may process it.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
 
T

TacoGod

So if it is a large directory, it could take awhile for the download to
complete... a thread would wait till this download is done then trigger
an event? is this the best way to go about doing this?

Thanks
 
T

TacoGod

I figured it out. I was using Serv-U ftp server... now that I have
switched to the Microsoft ftp server the code has been working great!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top