-
Sep 9th, 2009, 01:34 PM
#1
Thread Starter
Addicted Member
Uploading multiple files with inet
Hi all, please bear with me as i am new here!
I need to uplaod multiple files, in fact, all files in a local directory, and put them on a remote server.
I have the script working OK, and am able to put a single file at a time.
How can I make it upload all files the the local directory?
Following is the code I am using. I realise the PUT command is only for the one file, but I have tried all the *.* varieties i can think of, put it doesnt work.
Thank you in advance for your help and advice on this.
Code:
Inet1.AccessType = icUseDefault
Inet1.URL = myftp
Inet1.UserName = myusername
Inet1.Password = mypassword
Inet1.RequestTimeout = 40
Inet1.Execute , "put c:/test.txt test.txt"
Do While Inet1.StillExecuting
DoEvents
Loop
Inet1.Execute , "CLOSE"
MsgBox "Files uploaded succesfully...", , "Server Message"
-
Sep 9th, 2009, 02:42 PM
#2
Frenzied Member
Re: Uploading multiple files with inet
does that code actually work ?... not sure but i believed you have to actually send the file data too?
but if it works you would have to just create a loop to repeate the line from execute to loop
- i dont work with ftp so im not certain on said point above, but check the contents of the remote file - make sure its not blank... im not sure if inet does it all for you...
-
Sep 9th, 2009, 02:46 PM
#3
Thread Starter
Addicted Member
Re: Uploading multiple files with inet
hi, yes, it definately works OK.
im not sure how to do that, how does it:
know when to end?
or how many files are in the local directory?
thnaks
-
Sep 9th, 2009, 02:57 PM
#4
Frenzied Member
Re: Uploading multiple files with inet
k one way....
in a module - to find the files....
Code:
option explicit
Public Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
Public Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Public Const MAX_PATH = 260
Public Const MAXDWORD = &HFFFF
Public Const INVALID_HANDLE_VALUE = -1
Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_SYSTEM = &H4
Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Public Sub FindFilesNow(Path As String, SearchStr As String, bSearchSub As Boolean, _
ByRef FindMyFiles() As String, Optional ByVal lblCapt As Label)
If Not lblCapt Is Nothing Then
lblCapt.Caption = "Path: " & Path
lblCapt.Refresh
End If
Dim hSearch As Long ' Search Handle
Dim WFD As WIN32_FIND_DATA
Dim Cont As Integer
If Right(Path, 1) <> "\" Then Path = Path & "\"
Cont = True
hSearch = FindFirstFile(Path & "*", WFD)
If hSearch <> INVALID_HANDLE_VALUE Then
Dim aPat() As String, iFilters As Integer
aPat() = Split(SearchStr, "|")
iFilters = UBound(aPat())
Dim FileName As String, iEntry As Integer, iCnt As Integer
Do While Cont
FileName = StripNulls(WFD.cFileName)
' Ignore the current and parent directories.
If (FileName <> ".") And (FileName <> "..") Then
' Check for if it is a directory
If GetFileAttributes(Path & FileName) And FILE_ATTRIBUTE_DIRECTORY Then
' if it is a directory, search sub directories
If bSearchSub Then
Call FindFilesNow(Path & FileName & "\", SearchStr, bSearchSub, FindMyFiles(), lblCapt)
If Not lblCapt Is Nothing Then
lblCapt.Caption = "Path: " & Path
lblCapt.Refresh
End If
End If
ElseIf Dir$(Path & FileName) <> Empty Then
For iCnt = 0 To iFilters
If LCase(FileName) Like LCase(aPat(iCnt)) Then
iEntry = UBound(FindMyFiles()) + 1
ReDim Preserve FindMyFiles(iEntry)
FindMyFiles(iEntry) = Path & FileName
Exit For
End If
Next iCnt
End If
End If
Cont = FindNextFile(hSearch, WFD) 'Get next subdirectory.
Loop
End If
Cont = FindClose(hSearch)
End Sub
then call it like this....
spattmch = "*.*" or "*.gif" or w/e
the function is coded to allow "*.gif|*.wav" ETC too.. use | to split...
Code:
Dim aMyFiles() As String
ReDim aMyFiles(0) As String
FindFilesNow txtPath.Text, spattmch, IIf(chkSubDir.Value = vbChecked, True, False), aMyFiles(), lblStatus(0)
' items used in the loop
Dim ifiles As Integer
ifiles = UBound(aMyFiles())
If ifiles > 0 Then
dim iCur as integer
for icur = 1 to ifiles
' do your upload here
' you may need to use "DoEvents"
' to get the file name - sfilepath = aMyFiles(iCur), sTrack will be the file name on its own
sTrack = Right$(sFilePath, Len(sFilePath) - InStrRev(sFilePath, "\"))
next iCur
end if
' to get the file name - sfilepath = aMyFiles(iCur), sTrack will be the file name on its own
sTrack = Right$(sFilePath, Len(sFilePath) - InStrRev(sFilePath, "\"))
luckily i just used this code on my own app, so its just copy and pasted, so edit it to your needs
oh also... the highlighted parts you may want to remove from your code etc
Last edited by wpearsall; Sep 9th, 2009 at 03:01 PM.
Reason: just noticed some code that is for my app
Wayne
-
Sep 9th, 2009, 03:00 PM
#5
Thread Starter
Addicted Member
Re: Uploading multiple files with inet
wow that looks complicated!
many thanks, i'll go through it, hopefully i'll manage to understand it!
Shame it doesnt just support a simple "put *.*" !! but i guess that would have been too easy!
thansk agian
-
Sep 9th, 2009, 03:15 PM
#6
Frenzied Member
Re: Uploading multiple files with inet
im not sure, but this way at least you can put some sort of status txt...
you dont need to edit the module code [except you may want to remove the highlighted bit]
its only the code in the second bit you need to worry about.
oh also let me explain....
Code:
' Path to search, Pattern... (im guessing you want *.*), Search sub directories? True / False, aMyFiles() < Array the results go to a label control for the cur directory being searched
FindFilesNow txtPath.Text, spattmch, IIf(chkSubDir.Value = vbChecked, True, False), aMyFiles(), lblStatus(0)
its done via aPI
a simpler way would be to use a file list box.... and just
for i=0 to filelistbox.listcount (i think) -1
' do the upload
next i
but if your using a inet im guessing you dont want people to see too much clutter
-
Sep 9th, 2009, 03:21 PM
#7
Frenzied Member
Re: Uploading multiple files with inet
vb Code:
File1.Path = App.Path ' or c:\wotever
File1.Pattern = "*.*" ' or *.gif etc
File1.Refresh
If File1.ListCount > 0 Then
Dim icur As Integer
For icur = 0 To File1.ListCount - 1
Debug.Print File1.Path & File1.List(icur)
Next icur
End If
IF you wanna use a hidden file list - no need for API [for some reason i forgot about that till i psted that code above
File1.List(icur) <<< just the file name
- but note its not easy to search subdirectories with a file list... the api returns every file on c:\ if you just post C:\ - but i believe the code is limited to like 65000 files
-
Sep 9th, 2009, 10:51 PM
#8
Re: Uploading multiple files with inet
Or just use the Dir$() function. See the VB6 manual.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|