我在网上查了下载的方法,有很多种,试了这个能下载到本地,但是文件的字节是0,请高手帮我看看是什么问题呢。
(困惑好几天了)
代码如下
Function downFile(Inet1 As Inet, url As String, dest As String) As Boolean
On Error GoTo er1
Dim bytes() As Byte
bytes() = Inet1.OpenURL(url, icByteArray)
Dim tempS
Open dest For Binary Access Write As #2
Put #2, , bytes()
Close #2
downFile = True
Exit Function
er1:
MsgBox Err.Description
downFile = False
End FunctionPrivate Sub Command1_Click()
downFile Inet1, "ftp://gfgl:[email protected]/00000005GF01.jpg", "C:\TEMP\1.jpg"
End Sub
(困惑好几天了)
代码如下
Function downFile(Inet1 As Inet, url As String, dest As String) As Boolean
On Error GoTo er1
Dim bytes() As Byte
bytes() = Inet1.OpenURL(url, icByteArray)
Dim tempS
Open dest For Binary Access Write As #2
Put #2, , bytes()
Close #2
downFile = True
Exit Function
er1:
MsgBox Err.Description
downFile = False
End FunctionPrivate Sub Command1_Click()
downFile Inet1, "ftp://gfgl:[email protected]/00000005GF01.jpg", "C:\TEMP\1.jpg"
End Sub
先放在浏览器地址栏里面试试
我用的是VB
Inet1.Execute "ftp://gfgl:[email protected]", "GET B564801.jpg C:\TEMP\B564801.jpg"
right1 = Inet1.StillExecuting
Do While right1
right1 = Inet1.StillExecuting
DoEvents
Loop
这个用户对文件的权限是读写删
Private Function GetFtpUpdateFile() As Boolean
'获取FTP中的更新文件
Dim lngInet As Long
Dim lngInetConn As Long
Dim lngRet As Long
lngInet = 0
lngInetConn = 0
lngRet = 0
lngInet = InternetOpen(vbNullString, 1, vbNullString, vbNullString, 0&)
If lngInet Then
lngInetConn = InternetConnect(lngInet, 服务器IP, 端口, 用户名, 密码, 1, 0, 0)
If lngInetConn Then
lngRet = FtpGetFile(lngInetConn, 文件名, 0, 0, 1, 0)
InternetCloseHandle lngInetConn
End If
InternetCloseHandle lngInet
End If
If lngRet = 0 Then
GetFtpUpdateFile = False
Exit Function
End If 。。
另外这是一个自定义的函数吧,在按钮的单击方法中是不是直接用就可以了GetFtpUpdateFile()
这里面是不是还有几个是自定义的函数吧