Forum Discussion

ssa's avatar
ssa
Occasional Contributor
11 years ago

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...
  • HKosova's avatar
    11 years ago


    file is not sent to the destination
    Does your ftpConnection.bat file has the lcd command to specify the local folder that contains the files for upload? Like this:



    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.



    the command prompt exits immediately so unable to see the message.
    To leave the command prompt window open after running the command, use .Run("cmd /k command"):



    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);