473,386 Members | 1,817 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,386 software developers and data experts.

How to check that directory exist on ftp server or not?

Dear All,

I want to write a function of bool type to check whether a directory exist on ftp server or not..........I've googled it so much but couldn't get the solution......Currently i am using
Expand|Select|Wrap|Line Numbers
  1. WebRequestMethods.Ftp.GetDateTimestamp;
but this function return false in both cases either directory exist or not..............And another function
Expand|Select|Wrap|Line Numbers
  1. WebRequestMethods.Ftp.PrintWorkingDirectory;
which return true for every case either directory exist or not??????Can anyone point me in the right direction.

Thanks,
Aamer.
Feb 13 '12 #1
1 11729
PsychoCoder
465 Expert Mod 256MB
Here's one option you have for solving your issue using the FtpWebRequest and FtpWebResponse classes built into the .NET Framework

Expand|Select|Wrap|Line Numbers
  1. public bool DoesExist(string file)
  2. {
  3.     var ftpRequest = (FtpWebRequest)WebRequest.Create (string.Format("{0}/{1}","ftp://ftp.domain.com",file));
  4.     ftpRequest.Credentials = new NetworkCredential("username", "password");
  5.     ftpRequest.Method = WebRequestMethods.Ftp.GetFileSize;
  6.  
  7.     try
  8.     {
  9.         FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
  10.         return true;
  11.     }
  12.     catch (WebException ex)
  13.     {
  14.         FtpWebResponse ftpResponse = (FtpWebResponse)ex.Response;
  15.         if (ftpResponse.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
  16.         {
  17.             return false;
  18.         }
  19.     }
  20. }
Feb 15 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Lin Ma | last post by:
Greetings, Is it possbile to check a file exist without using Server.CreateObject("Scripting.FileSystemObject") in asp page?? The reason is our hosting company turn that function off for...
6
by: mark4asp | last post by:
Hello, Is there a simple way to check whether a database driver is available on a remote server? I only have ftp access so I can only run ASP scripts. An ASP application on a host has...
3
by: Bill | last post by:
Using ASP in a VBScript environment, how can I check the protection on a directory, or a particular file?
4
by: Steven | last post by:
Does anyone know if there is a way to check the access permissions of different users using C#? I need to know if a user has full control or if they have read only access or none to a certain...
4
by: Prasanth Raveendran | last post by:
Through an ASP.Net page I want to browse a shared folder. So i used directory.exist(\\machinename\sharename) but it returns false even if the directory exist. please help me -- Prasanth...
10
by: Li Pang | last post by:
Hi Anybody knows how to check a network server is available (pingable) Many thanks in advance.
4
by: Jim Renton | last post by:
Hi everyone How do you detect if directory exist and if it doesn’t how do you create one Thank Ji
5
by: OldBirdman | last post by:
I want to manage images to use on my form, multiple images per record (row in primary table). I will put these images in a folder, not as part of a table. There may be 12,000 rows in the table,...
6
by: Raghunandan24 | last post by:
Hi, Can you tell me how to check if tomcat server is running. Is there a command i can use. Thanks, Raghu
1
by: Adya | last post by:
Hi all, I have a list of files starting with a 4 digit code as below, 1) MI01_xxxx_xxxxx.pdf 2) MI01_xxx.pdf 3) MI01_xxxxx.pdf 4) MI03_xxxxx_xxxxx_xxxx.pdf 5) MI04_xxxxxxx_xxxx.pdf 6)...
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: 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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.