473,387 Members | 1,745 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.

ftp question using article id 832679

ps
I am using this article to get a list of files in a directory using ftp.
If I run the code without some kind of delay, I only get about half the
files. If I put a debug.write statement it returns all the files. I think
this may be some kind of timing issue. Can anyone help?
URL:http://support.microsoft.com/?scid=kb;EN-US;832679
Here are the two sections of code that I am using:

'Return a list of files from the file system. Return these files in a
string() array.

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

Dim strCmd As String

If sMask Is Nothing Then

strCmd = "NLST"

'strCmd = "LIST"

Else

strCmd = "NLST " & sMask

End If

m_sMes = ""

'Check to see 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)

SendCommand(strCmd)

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)

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

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

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

Debug.Write(ASCII.GetString(m_aBuffer, 0, bytes)) 'this will
affect the number of files returned. Maybe a timing issue?

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

Private Sub cmdRun_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdRun.Click

Dim strFileList() As String

Try

'URL:http://support.microsoft.com/?scid=kb;EN-US;832679

ftpServer = New xxxFTP.clsFTP("IP Address", ".", "userId",
"password", 21)

If ftpServer.Login() Then

MessageBox.Show("sucessful login")

'strFileList length will be 88 (files) without the debug.write
statement and 157 with the debug statement

strFileList = ftpServer.GetFileList(Nothing) 'no mask

'strFileList = ftpServer.GetFileList("*.*") 'only files with
extension

Me.lstFiles.Items.Clear()

Dim str As String

For Each str In strFileList

If str.Trim <> "." And str.Trim <> ".." Then

Me.lstFiles.Items.Add(str)

End If

Next

Else

MessageBox.Show("unsucessful login")

End If

Catch ex As Exception

MessageBox.Show(ex.ToString)

Finally

ftpServer.CloseConnection()

End Try

End Sub
Jul 21 '05 #1
0 2007

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

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
1
by: Rajesh S | last post by:
Hi, Is anybody is know how to distingush a directoryname and filename from the list we obtain by giving FTP Command "NLST".? I am using a class as per the micosoft document...
4
by: Steve Richter | last post by:
can File.Copy be use to copy files from my PC to the file system at my shared hosting web site? If so, what is the format of the path name of the file on the web site? The idea being that if I...
5
by: Tim Smallwood | last post by:
I have a program I'm wanting to write that will open an accounting program, do a back up (This functionality is buiilt into this accounting program) and then take the backup file that is a result...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
0
by: ps | last post by:
I am using this article to get a list of files in a directory using ftp. If I run the code without some kind of delay, I only get about half the files. If I put a debug.write statement it returns...
1
by: Joris De Groote | last post by:
Hi, I'm using in a VB.NET program a few links to other computers to write or read from (\\192.168.2.5\Filez\ for example), now I have to go to that folder first and log in, otherwise, the...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
6
by: John Larson | last post by:
Hi All, I am some information from INSPEC database records in XML to build a relational database of my own. I am currently trying to extract information by doing an XSLT transform of the XML...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...

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.