我想在Unity 2017.1.2.p4中使用C#(Mono implementation - Stable .Net 3.5)访问FTP。
为了测试,我只是尝试访问FTP和列表目录。
public class FTPManager
{
private string host = null;
private string user = null;
private string pass = null;
public FTPManager(string hostIP, string userName, string password)
{
host = hostIP;
user = userName;
pass = password;
ServicePointManager.ServerCertificateValidationCallback += OnCertif;
}
public void Stop()
{
ServicePointManager.ServerCertificateValidationCallback -= OnCertif;
}
public void ListDirectory()
{
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(host);
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.EnableSsl = true;
request.Credentials = new NetworkCredential(user, pass);
try
{
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
Debug.Log(string.Format("Directory List Complete, status {0}", response.StatusDescription));
response.Close();
}
catch (Exception e)
{
Debug.LogException(e);
}
}
private bool OnCertif(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
}
}
但我总是有同样的错误:
错误:TlsException:身份验证或解密失败。 Mono.Security.Protocol.Tls.RecordProtocol.ProcessAlert(AlertLevel alertLevel,AlertDescription alertDesc)
Mono.Security.Protocol.Tls.RecordProtocol.InternalReceiveRecordCallback(IAsyncResult asyncResult)Rethrow as IOException:身份验证或解密失败。 Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback(IAsyncResult asyncResult)
寻找其他帖子,我看到身份验证是匿名或我的是正常。 此外,FTP需要TLS协议。
感谢您的帮助。
答案 0 :(得分:0)
我在尝试访问AWS lambda时遇到同样的问题。 3.5 .Net根本不支持新的tls协议。
我采用最简单的方法 - 只使用Unity WWW对象,它的效果非常好