加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

VB中如何实现上传文件的功能

(2017-11-15 17:12:08)
标签:

it

佛学

历史

情感

文化

分类: 软件技术

用script脚本 直接调用 FTP 命令实现上传文件到FTP服务器

代码如下:

'定义API函数
Const SYNCHRONIZE &H100000
Const INFINITE &HFFFFFFFF
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As LongByVal bInheritHandle As LongByVal dwProcessId As LongAs Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As LongAs Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As LongByVal dwMilliseconds As LongAs 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 LongpHnd As Long
pId Shell("ftp -n -s:" filename ".script" " ftp, vbHide)
pHnd OpenProcess(SYNCHRONIZE, 0, pId)
If pHnd <> Then
Call WaitForSingleObject(pHnd, INFINITE)
Call CloseHandle(pHnd)
End If
Kill filename ".script" '因为script脚本保存了帐号和密码,当传输完成后删除filename.script脚本
End Sub

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有