?
Solved

Need to loop on error until cleared using ChilkatFTP

Posted on 2008-10-01
5
Medium Priority
?
633 Views
Last Modified: 2013-12-09
Using the free version of ChilkatFTP to download PDFs from server to local folder.  Script genrally works fine, but after 2 or 3 files I get a run time error "Failed to get directory informatoin", failing at the line in the loop where it gets the name of the next file.  Chilkat states that the free version had some bugs, and rather than fix they now offer FTP2 for $150.  I'm using it for upload with no problems, but the download has this error.  If I use the FTP2 Active X controler instead of FTP, it works fine.  So looking for a method to trap this error, and loop back around to try again to get the file name until successful.

'******  	MOVE FILES FROM A FLAT FOLDER TO A SERVER
Const strDestFolderName = "D:\PDF FLAT\"		'   Where files go
 
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set objChilkatFTP = CreateObject("ChilkatFTP.ChilkatFTP.1")
 
' Do while 1=1
 
objChilkatFTP.Hostname = "ftp.servername.com"		' Source server
objChilkatFTP.Username = "userID"
objChilkatFTP.Password = "password"
 
objChilkatFTP.Passive = 1 ' Passive mode
 
'  Connect and login to the FTP server.
intSuccess = objChilkatFTP.Connect()
If (intSuccess <> 1) Then
    MsgBox objChilkatFTP.LastErrorText
    WScript.Quit
End If
 
objChilkatFTP.ListPattern = "*.pdf"		' Set file type as PDF
 
' Now go get files from server, then delete
 
n = objChilkatFTP.NumFilesAndDirs
If (n < 0) Then
    MsgBox objChilkatFTP.LastErrorText
    WScript.Quit
End If
 
If (n > 0) Then
 
    For i = 0 To n - 1
	
        fname = objChilkatFTP.GetFilename(i) '>> this is the line causing the error
	lcl_fname =	strDestFolderName & fname	' Add path to file name
 
        '  Download the file into the current working directory.
        success = objChilkatFTP.GetFile(fname,lcl_fname)
         If (success <> 1) Then
            MsgBox objChilkatFTP.LastErrorText
            WScript.Quit
         End If
 
        '  Now delete the file.
        success = objChilkatFTP.DeleteRemoteFile(fname)
        If (success <> 1) Then
            MsgBox objChilkatFTP.LastErrorText
            WScript.Quit
        End If
    Next
End If							' Terminates when list exhausted
 
objChilkatFTP.Disconnect		' All done; disconnect for now
 
' wscript.sleep 60000			' Restart in one minute
 
' Loop

Open in new window

0
Comment
Question by:Mike Caldwell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 22619597
Hi Mike, there's a possibility that the script is having problems getting the next file after deleting a file within the same loop.
Say "n" was 6, when you delete a file, "n" becomes 5 (for the total number of files available), so you'll probably get the error.

What I've done to try to get around that is to record each file name that was downloaded during the loop, then after the files have been downloaded, it goes back and deletes those files.

Regards,

Rob.
'******  	MOVE FILES FROM A FLAT FOLDER TO A SERVER
Const strDestFolderName = "D:\PDF FLAT\"		'   Where files go
 
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set objChilkatFTP = CreateObject("ChilkatFTP.ChilkatFTP.1")
 
' Do while 1=1
 
objChilkatFTP.Hostname = "ftp.servername.com"		' Source server
objChilkatFTP.Username = "userID"
objChilkatFTP.Password = "password"
 
objChilkatFTP.Passive = 1 ' Passive mode
 
'  Connect and login to the FTP server.
intSuccess = objChilkatFTP.Connect()
If (intSuccess <> 1) Then
    MsgBox objChilkatFTP.LastErrorText
    WScript.Quit
End If
 
objChilkatFTP.ListPattern = "*.pdf"		' Set file type as PDF
 
' Now go get files from server, then delete
 
n = objChilkatFTP.NumFilesAndDirs
If (n < 0) Then
    MsgBox objChilkatFTP.LastErrorText
    WScript.Quit
End If
 
If (n > 0) Then
 strFileNames = ""
    For i = 0 To n - 1
	
        fname = objChilkatFTP.GetFilename(i) '>> this is the line causing the error
        If strFileNames = "" Then
        	strFileNames = fname
        Else
        	strFileNames = strFileNames & VbCrLf & fname
        End If
	lcl_fname =	strDestFolderName & fname	' Add path to file name
 
        '  Download the file into the current working directory.
        success = objChilkatFTP.GetFile(fname,lcl_fname)
         If (success <> 1) Then
            MsgBox objChilkatFTP.LastErrorText
            WScript.Quit
         End If
 		
    Next
    
    arrFileNames = Split(strFileNames, VbCrLf)
    For i = 0 To UBound(arrFileNames)
    	 '  Now delete the file.
        success = objChilkatFTP.DeleteRemoteFile(fname)
        If (success <> 1) Then
            MsgBox objChilkatFTP.LastErrorText
            WScript.Quit
        End If
    Next
End If							' Terminates when list exhausted
 
objChilkatFTP.Disconnect		' All done; disconnect for now
 
' wscript.sleep 60000			' Restart in one minute
 
' Loop

Open in new window

0
 
LVL 1

Author Comment

by:Mike Caldwell
ID: 22638834
Hmmmm, Rob.  Put 25 files at the server for a test.  Then ran this code as-is, and it instantly deleted all of them at the server and did not download any of them!
0
 
LVL 1

Author Comment

by:Mike Caldwell
ID: 22641701
Rob, stability is very important.  I will have as many as eight PCs running these scripts, all but two unattended.  My business depends upon this, so think I'l just purchase a license to the FTP2 version and be done with it.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 22642647
>> it instantly deleted all of them at the server

That seems odd, seeing as the functionality should not have changed....you could comment out this line:

        success = objChilkatFTP.DeleteRemoteFile(fname)

so that it doesn't delete them, but should still download them, and see what happens....

But of course, purchasing the fully supported version may be better in the long run.

Regards,

Rob.
0
 
LVL 1

Author Closing Comment

by:Mike Caldwell
ID: 31502037
Already bought a license and will slepp better this way!  Thanks Ron.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the past decade, as Internet security has become a chief concern of IT professionals, one of the most common questions administrators and users ask is, “Which is more secure, SFTP or FTPS?” In short, both file transfer protocols offer a high…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question