Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2005

Tip: Looking for answers? Try searching our database.

Code only executes on Step Through

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike Barrett - 15 Dec 2005 14:03 GMT
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
needhelp - 15 Dec 2005 14:51 GMT
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
Armin Zingler - 15 Dec 2005 14:59 GMT
> I cannot post questions as "new question".

Use a newsreader like outlook express.

Armin
John Bailo - 15 Dec 2005 15:23 GMT
XP doesn't support IIS.

Get a copy of Apache/Tomcat.

> 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
John A. Bailo - 15 Dec 2005 17:41 GMT
> 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?)

>> 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
Goran Sliskovic - 15 Dec 2005 20:06 GMT
...

>        m_sMes = ""
>        Do While (True)
[quoted text clipped - 6 lines]
>            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
Mike Barrett - 15 Dec 2005 20:32 GMT
> No, it does not look correct to me:
>
[quoted text clipped - 8 lines]
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.