Click here to Skip to main content
15,921,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Am trying to create a directory and subdirectory using the below code but it throw exception.

C#
string Path :"ftp://1.1.1.1/server01/develop/test/files/name";
FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(new Uri(path));
requestDir.Method = WebRequestMethods.Ftp.MakeDirectory;
requestDir.Credentials = new NetworkCredential("sh", "se");
requestDir.UsePassive = true;
requestDir.UseBinary = true;
requestDir.KeepAlive = false;

FtpWebResponse response = (FtpWebResponse)requestDir.GetResponse();
Stream ftpStream = response.GetResponseStream();
ftpStream.Close();
response.Close();


Am getting the exception :
"The remote server returned an error: (550) File unavailable (e.g., file not found, no access).".


this code is work to do like pass the path like below
path1:"ftp://1.1.1.1/server01"
path2:"ftp://1.1.1.1/server01/develp"
path3:"ftp://1.1.1.1/server01/develp/test"
path4:"ftp://1.1.1.1/server01/develp/files"
path5:"ftp://1.1.1.1/server01/develp/files/name".


Am just wondering why its failing when it creates subdirectory ? any help please.

Thanks in Advance
Posted
Updated 8-Mar-12 14:34pm
v2
Comments
Sergey Alexandrovich Kryukov 8-Mar-12 21:21pm    
Were you able to create required directory using any available FTP client?
--SA
shan1395 8-Mar-12 22:03pm    
Yes i do have WSFTP client
shan1395 8-Mar-12 22:04pm    
Am thinking for an alternative and ugly method to loop thru each sub directory to create

C#
private static bool CreateFTPDirectory(string directory, string folders)
        {

            bool exito = true;

            string[] lstfolders = folders.Split('/');

            string pathftp = directory;
            foreach (string fol in lstfolders)
            {

                if (fol != "")
                {

                    try
                    {
                        pathftp += "/" + fol;
                        //create the directory
                        FtpWebRequest requestDir = (FtpWebRequest)FtpWebRequest.Create(new Uri(pathftp));
                        requestDir.Method = WebRequestMethods.Ftp.MakeDirectory;
                        requestDir.Credentials = new NetworkCredential("ftpbienesraices", "b13n3sr@1c3s");
                        requestDir.UsePassive = true;
                        requestDir.UseBinary = true;
                        requestDir.KeepAlive = false;
                        FtpWebResponse response = (FtpWebResponse)requestDir.GetResponse();
                        Stream ftpStream = response.GetResponseStream();

                        ftpStream.Close();
                        response.Close();
                    }
                    catch (WebException ex)
                    {
                        FtpWebResponse response = (FtpWebResponse)ex.Response;
                        if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
                        {
                            response.Close();
                            exito = true;
                        }
                        else
                        {
                            response.Close();
                            exito = false;
                        }
                    }
                }
            }

            return exito;

        }
 
Share this answer
 
Surely, it is not coding issue. It might be because of system issues.

Verify whether application ID has the rights to create a sub directory or not. If so, check the free space availability in the system.
 
Share this answer
 
Comments
shan1395 8-Mar-12 20:38pm    
thanks GanesanSenthilvel,if i use path1:"ftp://1.1.1.1/server01", then my code creates Server01 dir but when i use the whole path to create sub dir then throws error. i checked with admin i have read/write access for that.
shan1395 8-Mar-12 20:43pm    
even i tried with full control,still having the same issue
shan1395 8-Mar-12 22:13pm    
Hi Ganesan, can you please let me know how to check the application Id rights ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900