标题:请教internetwritefile的使用,急!
只看楼主
邵帅
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:20
帖 子:174
专家分:505
注 册:2012-8-27
结帖率:78.26%
已结贴  问题点数:15 回复次数:6 
请教internetwritefile的使用,急!
我在用internetwritefile上传文件时可以上传,但上传的文件为空,不知道出了什么问题,把代码贴上去,希望大神帮忙解决。
程序代码:
private Declare Sub InternetWriteFile Lib "wininet.dll" (ByRef hFile As Long, lpBuffer As Byte, ByVal dwNumberOfBytesToWrite As Long, ByRef lpdwNumberOfBytesWritten As Long)
Private Const BUFFERSIZE As Long = 255 '缓冲区大小
Public Function ftpuploadfile(slocal As String, sremote As String) As Boolean '''上传文件
Dim hFile As Long
Dim data(BUFFERSIZE - 1) As Byte '存放数据的缓冲区
Dim written As Long ''已写
Dim size As Long '总大小
Dim sum As Long '已经下载的大小
Dim lblock As Long '块数
ftpuploadfile = False
sum = 0
lblock = 0
hFile = FtpOpenFile(hconnection, sremote, GENERIC_WRITE, dwtype, 0) '打开文件
If hFile = 0 Then
    Errorout Err.LastDllError, "打开文件"
    Exit Function
End If
Open slocal For Binary Access Read As #1 '打开本地文件
size = LOF(1)
For lblock = 1 To size \ BUFFERSIZE '分块读写
    Get #1, , data
    InternetWriteFile hFile, data(0), BUFFERSIZE, written
'    If InternetWriteFile(hFile, data(0), BUFFERSIZE, written) = 0 Then '写
'        Errorout Err.LastDllError, "写文件"
'        MsgBox ("123445")
'        Close #1
'        Exit Function
'    End If
    DoEvents '''''''''''''''交出控制权
    sum = sum + BUFFERSIZE
    RaiseEvent filetransferprogress(sum, size) '触发filetransferprogress
Next lblock
ReDim Data2((size Mod BUFFERSIZE) - 1) As Byte '读写剩余部分
Get #1, , Data2
    InternetWriteFile hFile, Data2(0), size Mod BUFFERSIZE, written
'    If InternetWriteFile(hFile, Data2(0), size Mod BUFFERSIZE, written) = 0 Then '读
'        Errorout Err.LastDllError, "读文件剩余部分"
'        Close #1
'        Exit Function
'    End If
    sum = sum + size Mod BUFFERSIZE
    RaiseEvent filetransferprogress(sum, size) '触发filetransferprogress
    'MsgBox ("正在读写剩余部分" + "sum=" + CStr(sum) + "" + "size=" + CStr(size))
    Close #1
    InternetCloseHandle (hFile)
    ftpuploadfile = True
End Function


[ 本帖最后由 邵帅 于 2012-10-13 09:12 编辑 ]
搜索更多相关主题的帖子: 上传文件 希望 
2012-10-13 09:09
邵帅
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:20
帖 子:174
专家分:505
注 册:2012-8-27
得分:0 
我发现上面的InternetWriteFile hFile, data(0), BUFFERSIZE, written和InternetWriteFile hFile, Data2(0), size Mod BUFFERSIZE, written根本没起到什么作用,是不是InternetWriteFile的声明有问题?

Figure out what you like. Try to become the best in the world of it.
2012-10-13 09:22
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1817
专家分:3681
注 册:2011-3-24
得分:15 
Declare Sub InternetWriteFile Lib "wininet.dll" (ByRef hFile As Long, lpBuffer As Any, ByVal dwNumberOfBytesToWrite As Long, ByRef lpdwNumberOfBytesWritten As Long) ?
没研究过wininet.dll之前是用winsock.dll做FTP类

不要選我當版主
2012-10-13 14:14
邵帅
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:20
帖 子:174
专家分:505
注 册:2012-8-27
得分:0 
winsock.dll做FTP类?!!!

Figure out what you like. Try to become the best in the world of it.
2012-10-13 16:18
邵帅
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:20
帖 子:174
专家分:505
注 册:2012-8-27
得分:0 
回复 3楼 wube
any或者byte结果都一样的。明明没有返回值的,为什么网上查的程序都有返回值?

Figure out what you like. Try to become the best in the world of it.
2012-10-13 16:25
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1817
专家分:3681
注 册:2011-3-24
得分:0 
你可以找一下FtpConnection的源码
我当初有用它来改写
不过网上抓到的源码有BUG
没支持二进位传输
要自己加写和几个可能会有溢出的地方
要调试一下

winsock.dll做FTP类
网路上也找得到源码
抓来改~哈哈哈~

不要選我當版主
2012-10-13 16:47
邵帅
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:20
帖 子:174
专家分:505
注 册:2012-8-27
得分:0 
回复 6楼 wube
首先多谢你的帮助。
。。。关于用internetwrite在网上的文章得不到什么信息。
如果再换另一种方法来开发FTP客户端,还要重头来啊,我其他的都做好了,就差这一个上传没解决了!

Figure out what you like. Try to become the best in the world of it.
2012-10-13 19:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-383066-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.087865 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved