即Inet1.Execute "", "PUT" &PAT_H &" " &USER
换成Inet1.Execute “”,"PUT" &PAT_H &space(1)&USER
参考文献:http://msdn.microsoft.com/en-us/library/aa733648(VS.60).aspx
用script脚本 直接调用 FTP 命令实现上传文件到FTP服务器。
代码如下:
'定义API函数Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFFFFFF
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Sub Command1_Click()
Dim filename As String
Dim ftp As String
Dim uname As String
Dim upin As String
ftp = InputBox("请输入服务器地址")
uname = InputBox("请输入帐号", , "anonymous")
upin = InputBox("请输入密码", , "IE@User")
filename = Timer() '取时间为文件名filename
Open filename & ".script" For Output As #1 '生成filename.script脚本,传输FTP用
Print #1, "user"
Print #1, uname
Print #1, upin
Print #1, "pwd"
Print #1, "hash"
Print #1, "put " & filename & ".txt"
Print #1, "quit"
Close #1
Open filename & ".txt" For Output As #1 '生成的filename.txt保存了combo1和text1的文字
Print #1, Text1.Text
Print #1, Combo1.Text
Close #1
DoEvents
'调用ftp命令传输,不需要inet或winsock控件
Dim pId As Long, pHnd As Long
pId = Shell("ftp -n -s:" & filename & ".script" & " " & ftp, vbHide)
pHnd = OpenProcess(SYNCHRONIZE, 0, pId)
If pHnd <> 0 Then
Call WaitForSingleObject(pHnd, INFINITE)
Call CloseHandle(pHnd)
End If
Kill filename & ".script" '因为script脚本保存了帐号和密码,当传输完成后删除filename.script脚本
End Sub
应该把Inet6.Cancel
和
Inet6.Execute
,
"CLOSE"
Inet6.Execute
,
"QUIT"
移到循环外面,比如:
Inet6.Cancel
For
i
=
0
To
List1.ListCount
-
1
Inet6.Execute
,
"get
MZ/"
&
List1.List(i)
&
"
D:\NCTEMP"
&
List1.List(i)
Do
While
Inet6.StillExecuting
DoEvents
Loop
Next
Inet6.Execute
,
"CLOSE"
Inet6.Execute
,
"QUIT"
下面的上传文件也一样。
FTP的get命令和put命令是可以连续执行的,无需下载一个文件就退出,然后又再登录下载下一个文件,这样不但效率低,而且很可能就是在这个不断登录的过程中造成文件下载异常。
限于条件,以上语句我无法测试,你自己试试看对不对。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)