Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zip and FTP Problem 1

Status
Not open for further replies.

evalesthy

Programmer
Oct 27, 2000
513
US
thread181-1493416

I'm using the following code"

Public Sub CreateEmptyZip(sPath)
Dim strZIPHeader As String

' header required to convince Windows shell that this is really a zip file
strZIPHeader = Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)

MsgBox "strZipHeader = " & strZIPHeader, vbInformation, "DevNote"

With CreateObject("Scripting.FileSystemObject")
.CreateTextFile(sPath).Write strZIPHeader
End With

End Sub

Private Sub cmdZipThenUploadFTP_Click()
'On Error GoTo Err_Handler
'zip code from Tek-tips thread181-1493416

Dim blnSuccess As Boolean
' True if successful, false if not

'Ok, easiest is to first create a blank zip file and then use the copyhere command to copy the files into it. To create a blank zip use something like:
DoCmd.Hourglass True

CreateEmptyZip "C:\Program Files\Bill Pro\BillProTest.zip"

With CreateObject("Shell.Application")
' Copy a file into the compressed folder.
.NameSpace("C:\Program Files\Bill Pro\BillProTest.zip").CopyHere _
"C:\Program Files\Bill Pro\BillPro_be.mdb"

'use this line if we want to zip all items in a folder into our zip file
'.NameSpace("c:\myDir\testzip.zip").CopyHere .NameSpace("C:\myDir\Files").Items
End With

'now upload to FTP
'example of call
'blnSuccess = 'FTPUploadFile(ByVal HostName As String, ByVal UserName As String, ByVal Password As String, byVal LocalFileName As String, ByVal RemoteFileName As String, ByVal sDir As String, ByVal sMode As String) As Boolean

blnSuccess = FTPUploadFile(" "datatrieve", "xxxx", "C:\Program Files\Bill Pro\BillProTest.zip", " "uploads", "Binary")

DoCmd.Hourglass False

If blnSuccess Then
MsgBox "FTP Zip & Upload completed.", vbInformation, "Success"
Else
MsgBox "FTP Zip & Upload failed.", vbCritical, "Warning"
End If


The FTPUpload works fine by itself. However, when I run the zip routine I have a problem. If I create the empty zip file (commenting out the NameSpace code that inserts the target file) the 'empty' zipfile uploads fine. Once I try to copy any real file (.txt or .mdb) into the empty zipfile the Upload code always fails. The file gets inserted into the empty zipfile (I can later extract it) but the send fails. Any ideas?
 
the Upload code always fails
Any error message ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV - thanks for the response. However, I have further information. If I break the routine into two separate processes run by separate cmdButtons - (step1) Zip then (step2) FTP the file will go. I think the problem is that the routine is trying to Send before the file is ready to go. Any ideas?
 
You still didn't answer my question ...
Anyway you may try to play with the DoEvents function.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV - Prior to your post I got the routine to work by implementing the 'sleep' routine in thread705-1522673 which incorporates DoEvents as you suggested. A pause of 15 seconds and my zip and ftp ran fine. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top