我正在使用以下代码将文件上传到 FTP,文件被上传 - 问题在于 xls、pdf 和视频文件,它们已损坏。Txt,sql保持不变,我直接在FTP中检查了这个。我在想它与 UTF8.GetBytes 有关吗?代码如下
Dim URI As String = Url & "/" & fileName
Dim ftp As System.Net.FtpWebRequest = CType(FtpWebRequest.Create(URI), FtpWebRequest)
ftp.Credentials = New System.Net.NetworkCredential(Username, Password)
ftp.Proxy = Nothing
ftp.KeepAlive = False
ftp.UsePassive = False
ftp.Method = System.Net.WebRequestMethods.Ftp.UploadFile
Dim sourceStream As New StreamReader(file.InputStream)
Dim fileContents As Byte() = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd())
sourceStream.Close()
ftp.ContentLength = fileContents.Length
ftp.UsePassive = True
Dim requestStream As Stream = ftp.GetRequestStream()
requestStream.Write(fileContents, 0, fileContents.Length)
requestStream.Close()
Dim response As FtpWebResponse = DirectCast(ftp.GetResponse(), FtpWebResponse)
任何帮助将不胜感激。