在FTP服务器上创建一个目录 [英] Creating a directory on FTP server

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

问题描述

我试图在我的FTP服务器上创建一个目录。谷歌搜索显示我这里这个问题。所以我遵循Jon写的答案,并且有:

  private static void MakeDirectory(string directory)
{
Log(创建目录...);

var request =(FtpWebRequest)WebRequest.Create(directory);

request.Method = WebRequestMethods.Ftp.MakeDirectory;
request.Credentials = new NetworkCredential(user,pass);

尝试
{
使用(var resp =(FtpWebResponse)request.GetResponse())//在此处发生异常
{
Log(resp。 StatusCode.ToString());


catch(WebException例外)
{
Log(ex.Message);




$ b

我有一个方法来验证目录是否存在:

  public bool DirectoryExists(字符串目录)
{
bool directoryExists;

var request =(FtpWebRequest)WebRequest.Create(directory);
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(user,pass);

尝试
{
using(request.GetResponse())
{
directoryExists = true;
}
}
catch(WebException)
{
directoryExists = false;
}
return directoryExists;
}

检查真的有效。如果存在,则返回 true ,否则返回 false 。但是,无论何时我运行我的 MakeDirectory(),我都会在上面提到的一行中遇到异常:

 远程服务器返回一个错误:(550)文件不可用(例如,文件未找到,无法访问)。 

我错过了什么吗?为什么 GetResponse()可用于我的目录检查,但不适用于我的 MakeDirectory()

解决方案

事实证明,这是运行我们Web服务器的公司的一个问题。他们昨晚做了一些FTP更新,不仅影响了我自己,还影响了他们的所有客户。他们已经解决了这个问题。它只是花了他们一天的时间才承认这是他们的错。


I'm trying to create a directory on my FTP server. Google search shows me this question here. So I followed what Jon wrote as his answer, and have:

    private static void MakeDirectory(string directory)
    {
        Log("Making directory...");

        var request = (FtpWebRequest)WebRequest.Create(directory);

        request.Method = WebRequestMethods.Ftp.MakeDirectory;
        request.Credentials = new NetworkCredential("user", "pass");

        try
        {
            using (var resp = (FtpWebResponse)request.GetResponse()) // Exception occurs here
            {
                Log(resp.StatusCode.ToString());
            }
        }
        catch (WebException ex)
        {
            Log(ex.Message);
        }
    }

I have a method to verify that the directory exists:

    public bool DirectoryExists(string directory)
    {
        bool directoryExists;

        var request = (FtpWebRequest)WebRequest.Create(directory);
        request.Method = WebRequestMethods.Ftp.ListDirectory;
        request.Credentials = new NetworkCredential("user", "pass");

        try
        {
            using (request.GetResponse())
            {
                directoryExists = true;
            }
        }
        catch (WebException)
        {
            directoryExists = false;
        }
        return directoryExists;
    }

The check actually works. If it exists, it returns true, if not, it returns false. However, whenever I go to run my MakeDirectory(), I get an exception on the line stated above:

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

Am I missing something? Why would the GetResponse() work for my directory check, but not for my MakeDirectory()?

解决方案

As it turns out, this was an issue on the part of the company who runs our web servers. They did some FTP update last night that affected not only myself, but all their clients. They have since fixed the problem. It just took them a day to admit that it was their fault.

这篇关于在FTP服务器上创建一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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