FTP服务器端是UTF-8编码的。我在客户端用VB实现,但是乱码,无法下载中文,具体代码如下。
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 Boolean
Private 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 If
End Sub
我觉得应该是转换为宽字符,用MultiByteToWideChar方法,但具体的还是不清楚。
希望有懂得同学帮忙,多谢!
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 Boolean
Private 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 If
End Sub
我觉得应该是转换为宽字符,用MultiByteToWideChar方法,但具体的还是不清楚。
希望有懂得同学帮忙,多谢!
解决方案 »
- WebBrowser1 如何禁止网页内的JS漂浮广告?
- 为什么我创建的数据库程序中不能更新、添加和 删除数据,点击保存也无
- 如何在VB6.0的环境下打开指定路径的文件?就象在文件夹双击打开一样
- 小弟公司進來一位新人,略懂一點兒VB,老大想要我給他進行一下培訓,各位大哥有沒有這方面的培訓資料啊?
- 求助:获得本地程序的IP数据包
- 【难】在VBA里,除了variables能长久存放数据,还有其他方法吗?
- VB菜鸟提问:有没有关于FlexGrid的基本操作介绍?
- 下拉组合框的问题,求大神不吝赐教
- 谁有工资管理程序
- 如何在WORD文件中自动打开图片文件
- EXCEL 2003注删
- vb怎样获取文件的md5址?
FtpGetFile有bug,不能用FtpGetFile。
替代方案如下:
To work around this issue, read and write the files manually to implement FTP file exchanges. To do this, follow these steps:
Open the connection by using InternetOpen, followed by InternetConnect.
Open the local file by using the CreateFile function.
Open the remote file by using the FtpOpenFile function.
Read the FTP or local file by using the InternetReadFile or ReadFile function, respectively.
Write to FTP or a local file by using the InternetWriteFile or WriteFile function, respectively.
Close the local file handle by using the CloseHandle function.
Close the FTP file handle by using the InternetCloseHandle function.