前提:使用 WinInet FtpGetFile 通过 FTP 将文件从 Linux 复制到 Windows。
目标:文件源自 ANSI,需要 Unicode。
进展:我遇到的唯一问题是我需要原始文件中的 LF 字符成为目标文件中的 CRLF 字符。
我努力了:
Public Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileW" (ByVal hFTP As Long, ByVal sRemoteFile As String, ByVal sNewFile As String, ByVal bFailIfExists As Boolean, ByVal lFlagsAndAttributes As Long, ByVal lFlags As Long, ByVal lContext As Long) As Boolean
Public Sub test(hConn as Long, strSrcPath as String, strDestPath as String)
'All code works other than the file not converting to having CR chars
ftpGetFile(hConn, StrConv(strSrcPath, vbUnicode), StrConv(strDestPath, vbUnicode), True, 0, 0, 0)
End Sub
- (转换失败)使用
FtpGetFile
方法 (Alias FtpGetFileW
) 的 Unicode 版本,使用StrConv(<string>, vbUnicode)
. 这些文件在行尾仅显示 LF 字符。 - (WORKS,手动)使用 WinSCP 手动复制文件。它会自动将输出文件设为 Unicode,但我找不到与此相关的方法/设置。我无法在工作中使用 WinSCP.dll,因为我无法注册它。
- (工作,慢慢地)使用解决方法。使用任一版本的
FtpGetFile
. 打开文件,读取变量,关闭文件,然后打开文件进行写入,写入Replace(variable,Chr(10),Chr(13)&Chr(10))
。此外,文件的大小似乎增加了一倍。
如何使用 WinAPI 函数获取文件并一次性转换(如果可能)?
相关文章:
FTP 传输后 Unicode 变为 ANSI 通过 FTP 将
ANSI 字符串写入 Unicode 文件