0
我正在使用下面的代碼上傳文件到FTP,文件上傳 - 問題是與xls,pdf和視頻文件,他們被損壞。 TXT,SQL保持不變,我已經直接在FTP中檢查過。我在想它與UTF8.GetBytes有關嗎?代碼如下使用Encoding.UTF8.GetBytes會破壞xls/video文件?
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)
任何幫助將不勝感激。
非常好,謝謝你的幫助:) – Judef