Hi, Nidhin;
Your formatting of the FTP Server URI looks correct, as does the setup of the FtpWebRequest to connect to the server.
Instead of polling the FTP Server using WebRequestMethods.Ftp.ListDirectory, have you tried using WebRequestMethods.Ftp.ListDirectoryDetails? Your FTP Request method would look like the following:
reqFTP.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
The WebRequestMethods.Ftp.ListDirectory would send the FTP NLIST command to the server, where as WebRequestMethods.Ftp.ListDirectoryDetails would send the FTP LIST command to the server. The FTP LIST command will return both the folders and files in the specified remote directory URI, and in case the remote directory on the FTP server is empty, it will also return the file nodes "." and "..". You will have to parse the results stream to get the remote directory contents, and your parsing should be able to differentiate between files and folders or directories.
With regards to how you're parsing the results, I can follow your higher level intent for looking at the text response from the FTP Server using the while() loop, but I can't quite see how the DataRow and corresponding DataSet objects are initialized and used to parse the remote directory contents actually returned.
If it's of any help, the following code fragment will initialize a StreamReder instance named remoteDirContents, which will then be used to format and "build up" a StringBuilder instance named remoteFiles, that will contain the full contents from executing the WebRequestMethods.Ftp.ListDirectoryDetails request. Each entry in the remote FTP directory parsed out will be in the string variable directoryData:
StreamReader remoteDirContents =
new StreamReader(response.GetResponseStream());
if (remoteDirContents == null)
{
}
bool finished = false;
string directoryData = string.Empty;
StringBuilder remoteFiles = new StringBuilder();
do
{
directoryData = remoteDirContents.ReadLine();
if (directoryData != null)
{
if (remoteFiles.Length > 0)
{
remoteFiles.Append("\n");
}
remoteFiles.AppendFormat("{0}", directoryData);
}
else
{
finished = true;
}
}
while (!finished);
I hope this was of help and interest.