【发布时间】:2012-09-07 18:25:03
【问题描述】:
我可以使用 .net ftp 成功上传文本文件 但现在想上传一个图形 (.png) 图像。 我应该如何设置流编码?
我拥有的文本(在 Apl 脚本中):
sourceStream ← '.net' ⎕new 'System.IO.StreamReader' 本地路径文件名 编码←'.NET' ⎕NEW 'System.Text.ASCIIEncoding'
然后我会从传输的二进制文件中丢失字节。 我也试过省略编码行。
干杯,美女
更多信息: 这是 Ascii 版本的核心,用 AplX .net 编写 - 它工作正常 - 现在我需要一个 BinaryReader 版本。 帮助表示赞赏
ftp←'.net' ⎕call 'System.Net.WebRequest.Create' Remotepathfilename
ftp.Method←'.net' ⎕call 'System.Net.WebRequestMethods+Ftp.UploadFile'
ftp.Credentials←'.net' ⎕new 'System.Net.NetworkCredential' Username Password
sourceStream ← '.net' ⎕new 'System.IO.StreamReader' Localpathfilename
encoding←'.NET' ⎕NEW 'System.Text.ASCIIEncoding'
fileContents ← encoding.GetBytes.⎕REF
sourceStream.ReadToEnd
sourceStream.Close
ftp.ContentLength ← fileContents.Length
:try
stream←ftp.GetRequestStream
:catchall
.....
这是我现在一直在尝试的,基于 vb 代码:
http://msdn.microsoft.com/en-us/library/system.io.file.openread#Y1035
Dim fs As FileStream
FileStream fs = File.OpenRead(path))
所以我试过了:
fileStream ← '.net' ⎕new 'System.IO.File'
fileStream.OpenRead Localpathfilename
以下是错误消息:
Constructor on type 'System.IO.File' not found.
DOMAIN ERROR
net_ftp_putfile[72] fileStream←'.net' ⎕new 'System.IO.File'
【问题讨论】:
-
使用 UTF8 编码。 ASCII 编码会导致问题,你最终会为了解决这个问题而费尽心思(这发生在我身上)
-
你的 ftp 代码是什么样的?