473,387 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Code only executes on Step Through

I am using VS 2005, VB.Net. I need to connect to an FTP server and get a
list of files. I plundered the following code from MSDN to accomplish this
task. It was part of a class called clsFTP:

Public Function GetFileList(ByVal sMask As String) As String()
Dim cSocket As Socket
Dim bytes As Int32
Dim seperator As Char = ControlChars.Lf
Dim mess() As String

m_sMes = ""
'Check if you are logged on to the FTP server.
If (Not (m_bLoggedIn)) Then
Login()
End If

cSocket = CreateDataSocket()
'Send an FTP command,
SendCommand("NLST " & sMask)

If (Not (m_iRetValue = 150 Or m_iRetValue = 125)) Then
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If

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

mess = m_sMes.Split(seperator)
cSocket.Close()
ReadReply()

If (m_iRetValue <> 226) Then
MessageString = m_sReply
Throw New IOException(m_sReply.Substring(4))
End If

Return mess
End Function

I connect to the FTP server perfectly. The rest of the functions in that
class work great, such as download, upload, etc.. Sadly, GetFileList only
returns the first file unless I step through, then it returns everything I
have. If I put a break point at the Do While line, then run again, it
executes perfectly. If I let it run, it gives me just the first file. The
mask I am using is also correct.

Any clues??? It is driving me insane. Does the code look tight? I have
tried everything I know how.

Thanks,
Mike
Dec 15 '05 #1
6 1336
I cannot post questions as "new question".

I am installing IIS on my win xp professional. However, there is no IIS
listed in the "add/remove windows components". Anybody can help?

Thanks
Dec 15 '05 #2
"needhelp" <ne******@discussions.microsoft.com> schrieb
I cannot post questions as "new question".

Use a newsreader like outlook express.
Armin
Dec 15 '05 #3

XP doesn't support IIS.

Get a copy of Apache/Tomcat.

needhelp wrote:
I cannot post questions as "new question".

I am installing IIS on my win xp professional. However, there is no IIS
listed in the "add/remove windows components". Anybody can help?

Thanks

Dec 15 '05 #4
John Bailo wrote:

XP doesn't support IIS.

Get a copy of Apache/Tomcat.
Oppps.

Correction.

XP Home doesn't support IIS.

Get a copy of Apache/Tomcat.

(Are you sure you have XP pro? Do you have the CD?)


needhelp wrote:
I cannot post questions as "new question".
I am installing IIS on my win xp professional. However, there is no
IIS listed in the "add/remove windows components". Anybody can help?

Thanks

Dec 15 '05 #5

"Mike Barrett" <mi*************@gmail.com> wrote in message
news:uy*************@TK2MSFTNGP09.phx.gbl...
....

m_sMes = ""
Do While (True)
Array.Clear(m_aBuffer, 0, m_aBuffer.Length)
bytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)
m_sMes += ASCII.GetString(m_aBuffer, 0, bytes)
' Console.WriteLine(m_sMes)
If (bytes < m_aBuffer.Length) Then
Exit Do
End If
Loop .... I connect to the FTP server perfectly. The rest of the functions in that
class work great, such as download, upload, etc.. Sadly, GetFileList only
returns the first file unless I step through, then it returns everything I
have. If I put a break point at the Do While line, then run again, it
executes perfectly. If I let it run, it gives me just the first file. The
mask I am using is also correct.
....

No, it does not look correct to me:
If (bytes < m_aBuffer.Length) Then
Exit Do
End If


This is not good criteria to leave loop as cSocket.Receive does not have to
return exact number of bytes that was requested. It can return less. It will
return number of bytes currently available (buffered by the OS). In case you
run it in debug mode and stop in breakpoint, you are giving network some
time to transfer more bytes then m_aBuffer can hold, so Receive will fill
whole buffer.

Regards,
Goran

Dec 15 '05 #6
No, it does not look correct to me:
If (bytes < m_aBuffer.Length) Then
Exit Do
End If


This is not good criteria to leave loop as cSocket.Receive does not have
to return exact number of bytes that was requested. It can return less. It
will return number of bytes currently available (buffered by the OS). In
case you run it in debug mode and stop in breakpoint, you are giving
network some time to transfer more bytes then m_aBuffer can hold, so
Receive will fill whole buffer.


'Do While (True)

Array.Clear(m_aBuffer, 0, m_aBuffer.Length)

bytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0)

m_sMes += ASCII.GetString(m_aBuffer, 0, bytes)

' Console.WriteLine(m_sMes)

'If (bytes < m_aBuffer.Length) Then

'Exit Do

'End If

'Loop

Commenting out the loop returned a perfect value.
Dec 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian Henry | last post by:
I have a project that was upgraded from ASP.NET 1.1 to ASP.NET 2.0. When I step through the page load even of one of my web forms, it calls a function in the app_config folder which is under the...
6
by: Mike Barrett | last post by:
I am using VS 2005, VB.Net. I need to connect to an FTP server and get a list of files. I plundered the following code from MSDN to accomplish this task. It was part of a class called clsFTP: ...
7
by: Robert W. | last post by:
I'm developing a C# WinForms app. My main EXE is referencing a DLL that I call "DataObjects.dll". I'm trying to step through each line of code to track down a bug. When a call is made to a...
1
by: jasonM | last post by:
Hi, I'm having an unusual bug using VBA in excel. Specifically, I'll include a line of code, but the line of code won't run when I play the macro. The unusual thing is that if I step through the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.