这是wininet.dll声明函数:
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, _
ByVal lAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, _
ByVal lFlags As Long) As Long
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
(ByVal hInternetSession As Long, _
ByVal sServerName As String, _
ByVal nServerPort As Integer, _
ByVal sUsername As String, _
ByVal sPassword As String, _
ByVal lService As Long, _
ByVal lFlags As Long, _
ByVal lContext As Long) As Long
Private Declare Sub FtpCreateDirectory Lib "wininet.dll" _
Alias "FtpCreateDirectoryA" _
(ByVal hConnect As Long, _
ByVal lpszDirectory As String)
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" _
(ByVal hConnect As Long, _
ByVal lpszDirectory As String) As Boolean
这是我的代码:
If FtpSetCurrentDirectory(hConnect, sDir) = False Then
j = CountOccurrences(sDir, "/")
Debug.Print "dir = " & sDir
Debug.Print "j = " & j
For i = 1 To j
If i = 1 Then
intOccChar = InStr(1, sDir, "/")
Else
intOccChar = InStr(intOccChar + 1, sDir, "/")
End If
Debug.Print "for i=" & i & " intOccChar = " & intOccChar
Debug.Print Left(sDir, intOccChar)
Debug.Print FtpSetCurrentDirectory(hConnect, Left(sDir,(intOccChar)))
If FtpSetCurrentDirectory(hConnect, Left(sDir, (intOccChar))) = False Then
Call FtpCreateDirectory(hConnect, Left(sDir, (intOccChar)))
End If
Next
End If
Call FtpSetCurrentDirectory(hConnect, sDir)
问题是::当ftp服务器上没有目录时,代码运行良好,但是当第一个目录存在时却没有创建子目录
这是即时Windows输出:
dir = AkhzaBank/80/2/Credit/
j = 4
for i=1 intOccChar = 10
AkhzaBank/
False
for i=2 intOccChar = 13
AkhzaBank/80/
False
for i=3 intOccChar = 15
AkhzaBank/80/2/
False
for i=4 intOccChar = 22
AkhzaBank/80/2/Credit/
False
注意:该代码可用于ftp上传和下载,唯一的问题是在ftp服务器上创建目录
预先感谢
答案 0 :(得分:0)
更新!!!!!!!!!!!!!!
我从我的问题中找到了解决方案
我不知道为什么,但是不知道这行
如果FtpSetCurrentDirectory(hConnect,Left(sDir,(intOccChar)))= False,则
防止在子文件夹中创建目录。我只是删除这行代码即可。
真正的解决方案
我的错误在于以下几行:
Private Declare Sub FtpCreateDirectory Lib "wininet.dll" _
Alias "FtpCreateDirectoryA" _
(ByVal hConnect As Long, _
ByVal lpszDirectory As String)
我必须声明FtpCreateDirectory为布尔函数而不是子函数!所以真正的声明函数是:
Private Declare Function FtpCreateDirectory Lib "wininet.dll" _
Alias "FtpCreateDirectoryA" _
(ByVal hConnect As Long, _
ByVal lpszDirectory As String) As Boolean