我有一个 FTP 域,我必须将文件 txt 上传到它的 FTP 服务器 FTP 域看起来像 ftpes://domain.com
,我从来没有看到 ftpes
之前,但是当我通过 FileZilla 上传时它成功上传了,但是如果我使用我的代码
FtpWebRequest ftpClient = (FtpWebRequest)FtpWebRequest.Create(FTPdestination+ i + ".txt");
ftpClient.Credentials = new System.Net.NetworkCredential(user, pass);
ftpClient.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
ftpClient.UseBinary = true;
ftpClient.EnableSsl = true;
ftpClient.KeepAlive = true;
System.IO.FileInfo fi = new System.IO.FileInfo(server+dtm+"_"+i+".txt");
ftpClient.ContentLength = fi.Length;
byte[] buffer = new byte[4097];
int bytes = 0;
int total_bytes = (int)fi.Length;
System.IO.FileStream fs = fi.OpenRead();
System.IO.Stream rs = ftpClient.GetRequestStream();
while (total_bytes > 0)
{
bytes = fs.Read(buffer, 0, buffer.Length);
rs.Write(buffer, 0, bytes);
total_bytes = total_bytes - bytes;
}
fs.Close();
rs.Close();
FtpWebResponse uploadResponse = (FtpWebResponse)ftpClient.GetResponse();
uploadResponse.Close();
错误信息是
URI prefix not recognized
请帮我解决我的问题。
最佳答案
ftpes://
不是标准协议(protocol)前缀。但它被一些 FTP 客户端识别为“基于 TLS/SSL 的显式 FTP”。
使用 FtpWebRequest
,您可以通过使用标准 ftp://
协议(protocol)前缀并设置 EnableSsl = true
(您已经执行的操作)来指定它。
另见 Does .NET FtpWebRequest Support both Implicit (FTPS) and explicit (FTPES)?
关于c# - ftpe ://URI prefix is not recognized by FtpWebRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48897385/