I've had this happen to me a few times...and I was thinking an IF or WHILE statement might help.
Something like:
BTW...wonderful program overall...saved my butt from some painful batch scripting.
Something like:
Code: Select all
I dunno what the return code of the TYPE command is tho, or if there is a better DOS command to use...?$TEST_EXIST=EXEC("type C:\name_of_file")
IF ($TEST_EXIST!="0")
OPENHOST(xx,yy,zz)
GETFILE(name_of_file)
ELSE
...
END IF
BTW...wonderful program overall...saved my butt from some painful batch scripting.
Hi Forest,
Yes, this is a possible workaround and it should work. "type" returns 0 if the file exists, if not it returns 1.
Regarding to the timout issues, in the next releases I'll try to make ScriptFTP more fault tolerant, at least try to reconnect a couple of times before droping an error. In the meantime, checks like this one should be used...
Thanks for the feedback.
Yes, this is a possible workaround and it should work. "type" returns 0 if the file exists, if not it returns 1.
or if there is a better DOS command to use...?You could also use "dir". This way:
Code: Select all
$TEST_EXIST=EXEC("dir C:\name_of_file_or_wildcard")
# If no file matches the dir statement the returned value
# will be 1, otherwise 0
IF ($TEST_EXIST!="0")
OPENHOST(xx,yy,zz)
GETFILE(name_of_file)
ELSE
...
END IF
Regarding to the timout issues, in the next releases I'll try to make ScriptFTP more fault tolerant, at least try to reconnect a couple of times before droping an error. In the meantime, checks like this one should be used...
Thanks for the feedback.
liked Script FTP? Try our other product Email Parser
Thanks for the info on using DIR, I decided to incorporate that instead. Much cleaner that the potential output of TYPE.
Here's what I have so far, I hope this helps out some other people. I only have to move 4 files around, so this would be a lot of work for people with lots of files to get/put.
Here's what I have so far, I hope this helps out some other people. I only have to move 4 files around, so this would be a lot of work for people with lots of files to get/put.
Code: Select all
You said ##Use C:\ftp_temp for downloaded files create the folder if it doesn't exist
$change_path=LOCALCHDIR("C:\ftp_temp")
IF($change_path!="OK")
EXEC("mkdir C:\ftp_temp")
END IF
### Get b_Execs file and make sure it exists on local drive or get it again ###
PRINT("Connecting to FTP server to get b_Execs file")
$attempt="0"
:file1
$result1=OPENHOST($SITE1, $USER1, $PASS1)
CHDIR("/d:/DAFC_APP/ftp/company/EXPORT")
GETFILE("b_Execs_".$DATE."_COMPANY.csv")
## Something went wrong with the connection, try it again from the top
IF($result1!="OK")
 $attempt=$attempt+1
 PRINT("!!Error!! Could not connect to FTP server! Trying again in 10 seconds. This is attempt #".$attempt)
 SLEEP(10)
 GOTO :file1
END IF
CLOSEHOST
$exist1=EXEC("dir c:\ftp_temp\b_Execs_".$DATE."_COMPANY.csv")
## Make sure file exists locally, if not start over from the top.
IF($exist1!="0")
GOTO :file1
END IF
In the meantime, checks like this one should be used...Does that imply you have some better/cleaner methods up your sleeve? =)
Hi Forest,
Nice script Thanks a lot.
Nice script Thanks a lot.
Does that imply you have some better/cleaner methods up your sleeve? =)hehe I only have some ideas on how ScriptFTP should handle timeouts and disconnections internally and automatically reconnect, nothing done yet, just sketches. The current innards of ScriptFTP make automatic reconnection a bit difficult to implement without making the C++ code a complete mesh of if--else statements. If you have some knowledge of software development this may sound familiar to you.
liked Script FTP? Try our other product Email Parser
I'll leave the software dev to people who know what they are doing... I learned how to program while using a MUD client and later in Java and shell scripts, but even then I wasn't writing anything complicated.
My script went from 96 lines to 190 in 9 days and it was easier for me to start from a blank notepad++ rather than wrangle with the existing stuff. You've probably got a few more lines than that to work with...
My script went from 96 lines to 190 in 9 days and it was easier for me to start from a blank notepad++ rather than wrangle with the existing stuff. You've probably got a few more lines than that to work with...
- All times are UTC -