VB编写个程序上传文件到FTP

FTP站点为192.168.1.11用户名为admin密码为123456要上传的文件为A,B,C,D要求A,B,C文件要上传到FTP根目录下,D文件上传到改目录的a文件夹... FTP站点为192.168.1.11 用户名为admin 密码为123456
要上传的文件为A,B,C,D
要求A,B,C文件要上传到FTP根目录下,D文件上传到改目录的a文件夹中
请大家帮忙编写下,谢谢
展开
 我来答
149005501
推荐于2017-12-15 · TA获得超过8.6万个赞
知道顶级答主
回答量:7.9万
采纳率:90%
帮助的人:1.3亿
展开全部
首先,在VB工具栏中添加部件Microsoft Internet Transfer Control 6.0 ,之后工具箱会多一个Inet的控件。
拖放该控件到窗体上,设置控件中的属性
protocol : 2-icFTP
RemoteHost : 你的FTP服务IP或域名
RemotePort : 你的FTP端口
URL : 你的FTPURL地址
UserName和Password 这两个就不用说了

'窗体中添加一个文本框(text1)和一个按钮(Command1)代码如下:

Private Sub Command1_Click()
Dim isRight As Boolean
Dim filestr As String
filestr = app.path & "\A"
Inet1.Execute "", "PUT " & filestr & " /A"
isRight = Inet1.StillExecuting '获取当前是否仍然在执行命令
Do While isRight
isRight = Inet1.StillExecuting
DoEvents
Loop
filestr = app.path & "\B"
Inet1.Execute "", "PUT " & filestr & " /B"
isRight = Inet1.StillExecuting '获取当前是否仍然在执行命令
Do While isRight
isRight = Inet1.StillExecuting
DoEvents
Loop
filestr = app.path & "\C"
Inet1.Execute "", "PUT " & filestr & " /C"
isRight = Inet1.StillExecuting '获取当前是否仍然在执行命令
Do While isRight
isRight = Inet1.StillExecuting
DoEvents
Loop
filestr = app.path & "\D"
Inet1.Execute "", "PUT " & filestr & " /a/D"
isRight = Inet1.StillExecuting '获取当前是否仍然在执行命令
Do While isRight
isRight = Inet1.StillExecuting
DoEvents
Loop
End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
text1.Text = text1.Text + CStr(State)
Select Case State
Case 11
text1.text ="在与主机通信的过程中发生了错误"
Case 12
text1.Text = "上传完成"
End Select
End Sub
蜜桃追剧吧
推荐于2016-11-09 · TA获得超过4616个赞
知道小有建树答主
回答量:935
采纳率:100%
帮助的人:67.2万
展开全部
VB编写个程序上传文件到FTP,可用下面程序:
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()
Open filename & ".script" For Output As #1
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
Print #1, Text1.Text
Print #1, Combo1.Text
Close #1
DoEvents
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"
End Sub
为了不重复文件名,取时间为文件名filename,生成filename.script脚本,传输FTP用,生成filename.txt保存了combo1和text1的文字,调用ftp命令传输,不需要inet或winsock控件,API是SHELL WAIT功能,因为script脚本保存了帐号和密码,当传输完成后删除filename.script脚本,如果用inet不如这个简单,毕竟FTP不是自己写的,不管PASV与否都正常使用,唯一就是密码保存要等传输完成,FTP是文本传输协议,与HTTP不一样,不能写POST,实在想那样,VB做不了,需要手动创建数据包欺骗服务器。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式