ftp automation

ScriptFTP

The professional tool to automate FTP, SFTP, FTPS and schedule FTP batch jobs

The forum is now read only. Please, go to the the main ScriptFTP website if you need help.
Post here if you experience file transfer problems or unexpected errors.
I've had this happen to me a few times...and I was thinking an IF or WHILE statement might help.

Something like:
Code: Select all$TEST_EXIST=EXEC("type C:\name_of_file") IF ($TEST_EXIST!="0")  OPENHOST(xx,yy,zz)  GETFILE(name_of_file) ELSE ... END IF  
I dunno what the return code of the TYPE command is tho, or if there is a better DOS command to use...?

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.
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.
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.
Code: Select all##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  
You said
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.
Does that imply you have some better/cleaner methods up your sleeve? =)
hehe :D 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.
I'll leave the software dev to people who know what they are doing... :D 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... ;)