VB实现ftp下载UTF-8乱码问题
FTP服务器端是UTF-8编码的。
我在客户端用VB实现,但是乱码,无法下载中文,具体代码如下。
- VB code
Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _(ByVal sAgent As String, ByVal LAccessType As Long, ByVal sProxyName As String, _ByVal SProxyBypass As String, ByVal lFlags As Long) As LongPublic Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _(ByVal hInternetSession As Long, ByVal sServerName As String, _ByVal nServerPort As Integer, ByVal sUsername As String, _ByVal sPassword As String, ByVal lService As Long, _ByVal lFlags As Long, ByVal lContext As Long) As LongPublic Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, _ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, _ByVal dwContext As Long) As BooleanPublic Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _(ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _ByVal lpszRemoteFile As String, ByVal dwFlags As Long, _ByVal dwContext As Long) As BooleanPrivate Sub Command2_Click() ftpServer = "192.168.163.251" user = "admin" passwd = "admin" port = 2122 Dim file As String file = "补丁文件下载程序-时序图.vsd" file = "jftp.jar" 'file = "补丁升级软件结构图.doc" lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, _ vbNullString, vbNullString, 0&) If lnginet Then lnginetconn = InternetConnect(lnginet, ftpServer, 2122, _ user, passwd, 1, 0, 0) '1 ftp If lnginetconn Then MsgBox "connect ok!!!" blnRC = FtpGetFile(lnginetconn, file, "c:\aaa", 0, 0, FTP_TRANSFER_TYPE_BINARY, 0) If blnRC Then MsgBox "download ok!!!" Else MsgBox "download failed!!!" End If InternetCloseHandle lnginetconn InternetCloseHandle lnginet MsgBox "close ok!!!" Else MsgBox "can't connect" End If Else MsgBox "ftp wrong" End IfEnd Sub
我觉得应该是转换为宽字符,用MultiByteToWideChar方法,但具体的还是不清楚。
希望有懂得同学帮忙,多谢!
[解决办法]
尽可能不要用中文文件名,有些网段不支持 8-bit 字符传输。