?
Solved

How do I check if a ftp directory is empty?

Posted on 2011-04-19
4
Medium Priority
?
886 Views
Last Modified: 2013-11-26
Hello
I am writing an application to connect to a ftp server, and read the ftp files in a a ftp directory. How do I check if the ftp directory is empty or not? Any suggestions will be appreciate
0
Comment
Question by:Jeeck
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Amick
ID: 35425031
One way would be to examine the return from the ls command.
0
 

Author Comment

by:Jeeck
ID: 35425371
This is what I am doing
Dim strFileName  as string() = Strings.Split(newFTP.ListDirectory("/MyDirectory/")(0), vblf)I
This code works fine if I have files in the directory. But, of Course, if there are no files in the directory, it doesn't work anymore. I am thinking about checking  newFTP.ListDirectory("/MyDirectory/") first, but don't know. I am trying all combinations but not succes yet.
If newFTP.ListDirectoryDetail("/ClientUpdateLog/") Is Nothing Then

              '  Do nothing
 End If
Can you be specific about the Is command?
0
 
LVL 12

Accepted Solution

by:
Amick earned 2000 total points
ID: 35425843
Here's a discussion that you may find useful: http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/12e8de79-c544-4164-8c4e-0ba75fb9096f

Meanwhile, the fact that the statement is failing when there are no files allows you to use error handling to accomodate that situation, right?

Also you might consider using FtpWebResponse. Any data returned by the request, such as the list of file names returned for a ListDirectory request, is available in the stream returned by the GetResponseStream method. The length of the stream data can be obtained from the ContentLength property.  I believe a length of zero would tell you what you need to know.

0
 

Author Closing Comment

by:Jeeck
ID: 35426026
Just have to copy and paste. :-)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question