从Unity到FileZilla服务器进行通信

本文关键字:通信 服务器 FileZilla Unity | 更新日期: 2023-09-27 18:21:23

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

UriFormatException:无效URI:无效端口号System.Uri.Parse(UriKind类型,System.String uriString)System.Uri.ParseUri(UriKind类型)System.Uri.ctor(System.String uriString,布尔dontEscape)System.Uri.ctor(System.String uriString)recoveringX.UploadFile(System.String文件路径)重新合并X.OnGUI()

当m_Ftphosti给出时

ftp://+ip+portID

编辑:我更改了斜线字符,我不再有这个问题了。现在我的问题是,当我调用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!

从Unity到FileZilla服务器进行通信

您可以使用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