这应该很简单,并且上传作品。但是当我在 FTP 服务器上打开上传的文件时,它会显示二进制数据,这些数据只是一些看起来像 [][][][] 的奇怪字符,并且文件大小正确。如何添加表明该文件是 XML 的属性或标题?
public bool ProcessBatch(MemoryStream memStream)
{
bool result = true;
FTPaddress = DistributionResources.ftpServer;
CompleteFTPPath = DistributionResources.ftpPath;
request = (FtpWebRequest)FtpWebRequest.Create(FTPaddress + CompleteFTPPath);
request.Credentials = new NetworkCredential("username", "password");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
try
{
byte[] buffer = new byte[memStream.Length];
memStream.Read(buffer, 0, buffer.Length);
memStream.Close();
using (Stream reqStream = request.GetRequestStream())
{
reqStream.Write(buffer, 0, buffer.Length);
}
//Gets the FtpWebResponse of the uploading operation
response = (FtpWebResponse)request.GetResponse();
Console.WriteLine(response.StatusDescription); //Display response
}
catch(Exception ex)
{
result = false;
}
return result;
}
非常感谢你