【问题标题】:Filezilla c# 500 Syntax error, command unrecognizedFilezilla c# 500 语法错误,命令无法识别
【发布时间】:2015-11-23 08:54:29
【问题描述】:

我已经使用 Filezilla 创建了一个 ftp 服务器。我正在尝试使用 c# 代码上传单个文件。我的 cide 是一个非常简单的函数,叫做上传:

static void UploadFile(string filepath)
    {
     string m_FtpHost = "http://ip:port/";
     string m_FtpUsername = "userID";
     string m_FtpPassword = "pass";
     // Get an instance of WebClient
     WebClient client = new System.Net.WebClient();
     // parse the ftp host and file into a uri path for the upload
     Uri uri = new Uri(m_FtpHost + new FileInfo(filepath).Name);
     // set the username and password for the FTP server
     client.Credentials = new System.Net.NetworkCredential(m_FtpUsername, m_FtpPassword);
     // upload the file asynchronously, non-blocking.

     client.UploadFileAsync(uri, "STOR", filepath);
    }

    static void Main(string[] args)
    {
      UploadFile("file.pdf"); 
      Console.ReadKey();
    }

在 Filezilla 服务器 gui 中,我收到以下消息:

(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> STOR  /file.pdf HTTP/1.1
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 530 Please log in with USER and PASS first.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> Content-Type: application/octet-stream
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 500 Syntax error, command unrecognized.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> Host: ip:port
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 500 Syntax error, command unrecognized.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> Content-Length: 481868
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 500 Syntax error, command unrecognized.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> Expect: 100-continue
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 500 Syntax error, command unrecognized.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> Connection: Keep-Alive
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 500 Syntax error, command unrecognized.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> disconnected.

知道这里可能有什么问题吗? 编辑:我尝试在 UploadFile 中使用 ftp 更改 http。现在我收到以下信息:

(000019)11/23/2015 10:59:53 AM - chrathan user (ip)> 257 "/" is current directory.
(000019)11/23/2015 10:59:53 AM - user (ip)> TYPE I
(000019)11/23/2015 10:59:53 AM - user (ip)> 200 Type set to I
(000019)11/23/2015 10:59:53 AM - user (ip)> PASV
(000019)11/23/2015 10:59:53 AM - user (ip)> 227 Entering Passive Mode (ip with comma)
(000019)11/23/2015 10:59:53 AM - user (ip)> STOR file.pdf
(000019)11/23/2015 10:59:53 AM - user (ip)> 150 Opening data channel for file upload to server of "/file.pdf"
(000019)11/23/2015 10:59:53 AM - user (ip)> 550 can't access file.
(000019)11/23/2015 10:59:53 AM - user (ip)> disconnected.

EDIT2:基本上我尝试访问的文件夹是网络共享磁盘。当我更改为我的电脑中的本地文件夹时,一切正常。最后我的问题是如何访问网络共享磁盘?

【问题讨论】:

  • 如何将 WebRequest 与 WebRequestMethods.FTP.Put 一起使用?似乎登录过程不起作用。服务器请求您的授权凭据,答案是 Content-Type,因此,请使用正确的上传请求
  • 我将 http 更改为 ftp,我现在收到新的错误消息。

标签: c# server filezilla


【解决方案1】:

您的m_FtpHost 变量设置为使用http,它需要是ftp://ip:port/

这就是显示日志第一行的原因:STOR /file.pdf HTTP/1.1

【讨论】:

  • 您尝试上传的文件夹是否对运行 FileZilla 服务器的帐户具有写入权限?
  • 基本上是一个网络共享驱动器,因此它似乎不是那么简单。
  • 啊,我明白了。 FileZilla 论坛上的这篇关于设置 FileZilla 服务器以使用网络共享的粘性帖子可能会对您有所帮助:forum.filezilla-project.org/viewtopic.php?f=6&t=9200
  • 因此,实际上该链接建议在我的窗口中创建一个新用户并使用它来运行 filezilla 服务器服务。我说的对吗?
  • 这一切都取决于您的特定环境/域等。您不一定需要一个新帐户,您可以使用现有帐户,但从管理的角度来看,建议您这样做为此目的设立一个专用帐户。重要的是,FileZilla 运行的本地服务器帐户和您连接的远程网络共享都需要授予正确的权限。
猜你喜欢
  • 2014-02-08
  • 1970-01-01
  • 2015-12-15
  • 1970-01-01
  • 2011-10-25
  • 2015-03-28
  • 2022-01-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多