【问题标题】:Communicate from Unity to a FileZilla server从 Unity 与 FileZilla 服务器通信
【发布时间】:2015-11-10 10:05:32
【问题描述】:

我从 Unity 创建了一些文件,我想将它们发送到我创建的本地服务器(使用 FileZilla 服务器)。知道如何从我拥有的统一项目与我使用 FileZilla 创建的服务器进行通信吗?我正在尝试实现建议的代码,但出现以下错误:

UriFormatException:无效的 URI:无效的端口号 System.Uri.Parse(UriKind 种类,System.String uriString) System.Uri.ParseUri(UriKind 种类) System.Uri..ctor (System.String uriString, Boolean dontEscape) System.Uri..ctor (System.String uriString) recorgingX.UploadFile (System.String 文件路径) 记录X.OnGUI()

作为 m_FtpHost 我给了

ftp:// + ip + 端口号

编辑:我更改了斜杠字符,我不再遇到这个问题。现在我的问题是,当我调用UploadFile (outName); 时,它不会将其上传到服务器。我怎样才能检查发生了什么?建议的代码在 c# 项目中运行良好,但是当导入到 UNity 项目时它没有做任何事情。在 filezilla 服务器中,我收到以下内容:

10/2015 17:18:52 PM - (not logged in) (127.0.0.1)> USER userID
(000025)11/10/2015 17:18:52 PM - (not logged in) (127.0.0.1)> 331 Password required for chrathan
(000025)11/10/2015 17:18:58 PM - (not logged in) (127.0.0.1)> PASS ***********
(000025)11/10/2015 17:18:58 PM - (not logged in) (127.0.0.1)> 530 Login or password incorrect!

【问题讨论】:

  • 您说的是 Microsoft Unity 还是 Unity3D?
  • 有什么不同?我还没有听说过 Microsoft Unity。
  • 嗯,微软的 Unity 是一个依赖注入容器,而 Unity3D 是一个游戏引擎。我怀疑你的意思是游戏引擎。
  • 是的,这是有道理的。我正在使用 3d 引擎,并且我创建了一个简单的 gui,其中包含一些存储文件的按钮。我想将这些文件发送到我在 PC 中创建的 ftp 服务器。
  • 好的,问题解决了,是斜线的问题。 @Rob 感谢您的帮助。

标签: c# unity3d ftp filezilla


【解决方案1】:

您可以使用System.Net.WebClient 类将文件上传到 FTP 服务器。

这是一个如何做到这一点的理论示例。

using System;
using System.Net;

public string m_FtpHost = "ftp://myftpserver.com";
public string m_FtpUsername = "FTP username";
public string m_FtpPassword = "FTP password";

public void UploadFile(string filepath)
{
    // 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);
}

WebClient 和其他所需类的文档可以在 MSDN https://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx 上找到

【讨论】:

    猜你喜欢
    • 2020-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-05
    • 2011-09-23
    • 2021-12-29
    相关资源
    最近更新 更多