使用FTP上传二进制文件的最佳方法

时间:2013-09-17 14:11:16

标签: c# file ftp binary

我有一个图像文件。我使用ftp将其上传到我的服务器。这是最有效的方法吗?

System.Net.FtpWebRequest ftpClient =   (System.Net.FtpWebRequest)System.Net.WebRequest.Create( _serverPath + "/" + _filename);
ftpClient.Method = System.Net.WebRequestMethods.Ftp.UploadFile;
ftpClient.Credentials = new System.Net.NetworkCredential("ftp://website.ftp",  "thepassword");
ftpClient.UseBinary = true;
ftpClient.KeepAlive = true;
System.IO.Stream rs = ftpClient.GetRequestStream();
rs.Write(fileContents, 0, fileContents.Length);
rs.Close();
FtpWebResponse uploadResponse = (FtpWebResponse)ftpClient.GetResponse();
value = uploadResponse.StatusDescription;
uploadResponse.Close();

感谢任何人?

0 个答案:

没有答案