FTP上传二进制文件

时间:2014-01-17 20:48:11

标签: file-upload ftp binary

到目前为止,我可以使用以下代码将一些文件上传到我的服务器,你能帮我更改这段代码来上传二进制文件吗?感谢。

// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://sosoft.com/AES.file");

request.Method = WebRequestMethods.Ftp.UploadFile;


request.Credentials = new NetworkCredential("user.com", "xxxwALpH@J1rW"); 
// Copy the contents of the file to the request stream.

StreamReader sourceStream = new StreamReader("AES.file");
byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close(); 
request.ContentLength = fileContents.Length;


Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();

FtpWebResponse response = (FtpWebResponse)request.GetResponse();    
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

response.Close();

0 个答案:

没有答案