在ftp服务器中创建子文件夹 [英] create subfolders in ftp server

查看:118
本文介绍了在ftp服务器中创建子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图使用下面的代码创建一个目录和子目录,但它会抛出异常。



Hi,

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

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

推荐答案

当然,这不是编码问题。可能是因为系统问题。



验证应用程序ID是否有权创建子目录。如果是,请检查系统中的可用空间可用性。
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.


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;

        }


这篇关于在ftp服务器中创建子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆