做了一个FTP程序,用modWinInet.bas这种方式,主要功能就是从本地的一个目录上传文件到FTP服务器指定的目录里面.现在的问题是:由于要上传的目录不是固定的(以日期方式命名),需要上传的时候检查FTP服务器上有没有需要的文件夹,如果没有就要创建,比如今天上传的文件都是要上传到"20040322"这个文件夹里面,怎么判断有没有"20040322"这个文件夹,没有就自动创建.怎样能实现?
调试欢乐多
继续研究!
##################################
在FORM1加入inet1控件及一个Command按钮。
请确保你的inet1已经和FTP地址连接了。
在模块中定义folderFlag变量为布尔值(这是为了不引起混乱而设的)
然后给按钮加上CLICK事件
private sub command1_click()
folderName="MK"
folderFlag=true
inet1.execute ,"MKDIR " & folderName
do while inet1.stillExecuting=true
doEvents
loop
folderFlag=false
End sub
然后给inet1加上事件
private sub inet1_stateChanged(byVal state as integer)
select case state
case 12
'其他的连接代码略
dim tmpData as Variant
if folderFlag=true then
tmpData=inet1.getChunk(1024,icString)
if len(tmpData)=0 then
exit sub
end if
doEvents
msgbox “已经创建了目录"
end if
end select
end sub
呵,以前我是这样弄的,行得通,现在我电脑的VB有点问题,所以无法进行测试,如果有什么问题再给我留言吧。
另外有用API实现的方法吗?
我现在的FTP程序是调用wininet.dll里面的函数实现的,感觉用inet不是很稳定,以前做过,后来不用了.
Dim ftpServer As IADs
Dim ftpservice As IADs
Dim ComputerName As String
Dim I As Integer
I = 1
Dim hand As Boolean
hand = False
CheckFTPsite = False
ComputerName = getPcName()
Set ftpservice = GetObject("IIS://" & ComputerName & "/MSFTPSVC")
On Error GoTo errhandle
For Each ftpServer In ftpservice
Set ftpServer = Nothing
Set ftpServer = GetObject("IIS://" & ComputerName & "/MSFTPSVC/" & I)
If UCase(ftpServer.servercomment) = UCase("默认 FTP 站点") Then
Pot = ftpServer.serverbindings
oldstrPort = Pot(0)
CheckFTPsite = True
Set ftpServer = Nothing
Set ftpservice = Nothing
Exit Function
Else
I = I + 1
End If
Next
hand = True
errhandle:
If hand = False Then
CheckFTPsite = False
Else
CheckFTPsite = True
End If
Set ftpServer = Nothing
Set ftpservice = Nothing
End Function
你的代码不能运行,只有其中的一部分,,请补充一下,谢谢!