我有一个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前缀
请帮我解决我的案子。
答案 0 :(得分:3)
ftpes://
不是标准协议前缀。但某些 FTP客户端认为"显式FTP超过TLS / SSL" 。
使用FtpWebRequest
,您可以使用标准ftp://
协议前缀并设置EnableSsl = true
(您已经做过)来指定。
另见Does .NET FtpWebRequest Support both Implicit (FTPS) and explicit (FTPES)?