ssa
11 years agoOccasional Contributor
Unable to execute a batch file from TC using JS.
I am trying to execute a .bat file that opens a FTP connection to a server and put a file on specified location.
If i manually issue this command in the command prompt
C:\>ftp -i -s:ftpConnection.bat
It send out the mentioned file to the specified path.
But i am unable to execute this script(ftpConnection.bat) from TC.
I tied to it like below..
Sys.OleObject("WScript.Shell").Run("C:\\Windows\\System32\\ftp.exe -i -s:C:\\ftpConnection.bat");
It just opens a command prompt and the file is not sent to the destination. Event the command prompt exits immediately so unable to see the message.
Searched a bit and found below link but couldn't make it to server my purpose.
any idea how to do this form TC.
Thanks.
Does your ftpConnection.bat file has the lcd command to specify the local folder that contains the files for upload? Like this:file is not sent to the destination
lcd C:\MyFolder
mput *.txt
Without lcd, ftp looks for files in the current working folder, which in this case is your TestComplete project folder.
To leave the command prompt window open after running the command, use .Run("cmd /k command"):the command prompt exits immediately so unable to see the message.
Sys.OleObject("WScript.Shell").Run("cmd /k ftp -i -s:C:\\ftpConnection.bat", 1, false);
Or if you want to pause the script until the FTP transfer completes, use .Run(command, 1, true):
Sys.OleObject("WScript.Shell").Run("ftp -i -s:C:\\ftpConnection.bat", 1, true);