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.
Need help writing a script? Have any question about ScriptFTP?
Iam new to this product and I am running into a wall trying to get a simple .bat file to exec inside the script. The .bat expects 2 parameters to be passed to it and I can't seem the get the syntax correct. I am using variables that are created within the script itself which adds another level of complexity to the process. Here is the line out of the script
FTP Script
  1. EXEC("TSTcopy.bat "'.$BACKUP_source.$BACKtxt.'"  "'.$BACKUP_Dest.$BACKtxt.'')
The variables are the source and destination of a file copy .bat file and either I can't get it to recognize the .bat file as valid or the parameters are not passed as there value but the variable name.

Any insight that can be offered would be a great help
Hi Scott,

The correct way is:
FTP Script
  1. EXEC('TSTcopy.bat "'.$BACKUP_source.$BACKtxt.'"  "'.$BACKUP_Dest.$BACKtxt.'"')
In ScriptFTP, you can use the double quote character (") or a single quote character (') to delimit text strings. In this case, as you want to use double quotes inside the text string you have to use (') to delimit it. It sound like a tongue twister he he :) just copy and paste, it should work. If not, feel free to post here again.
Thanks that worked perfectly. I tried every combination of double and single quotes that seemed to make sense bases on the scripting examples and guide, but I have to admit I would have never thought about doing it that way.

Thanks again
Scott
Yes, don't worry. Sometimes it's a mess.
I'm trying to put a Windows file on a Unix server, then move and rename it to the right directory. This script puts the file into the Transfers directory for sure, but then the moving fails, returning an error code of '1' no matter what I try. Obviously something is wrong..... Can you help, please? The logfile contains this message: 'moveFile' is not recognized as an internal or external command, operable program or batch file. Well, I can't seem to use a bash inside the EXEC either, so what can I really execute?
FTP Script
  1. VERBOSE(ON)
  2. LOGTO("C:\LoggerNet\LoggerNet_CR1000_RPK01\Logs\TestLog.txt",APPEND)
  3. # Connect to FTP server
  4. SETPROTOCOL(FTPS_EXPLICIT_ENCRYPT_DATA)
  5. SETPASSIVE(DISABLED)
  6.  
  7. $oldFileName = "RPK01_MINUTEDATA.PRN"
  8. $date = GETDATE(FORMAT3)
  9. $newFileName = "../RPK01R/RPK01_" . $date . "-050100.Raw"
  10. OPENHOST("unixServer","userName","passwd")
  11.  
  12. CHDIR("Transfers")
  13. # Send new files
  14. PUTFILE("C:\WindowsPath\" . $oldFileName)
  15. # Transfer finished correctly, so lets try to move and rename the file
  16. $errorNum = EXEC('moveFile "'.$oldFileName.'"  "'.$newFileName.'"')
  17. PRINT($errorNum)
  18. #close the connection
  19.  
where the file named 'moveFile' is made executable and contains this bash code:
FTP Script
  1. #!/bin/bash
  2. mv $1 $2
Hello,

The EXEC command is used to launch a program in the computer where ScriptFTP is running, not in the FTP server. To move a file using FTP you have to use RENAMEFILE. Further info here:

https://www.scriptftp.com/d/ftp-file-commands/renamefile

Some FTP servers allow to launch programs in the server itself this way:
FTP Script
  1. RAWCOMMAND("SITE EXEC blabla.sh")
But it is usually deactivated for security reasons.
Thanks very much!.... Of course it works now - don't know why I was trying to do it the impossible way....... must have been the end of the day overload.
I have a batch file that I am trying to schedule to run with the program. The batch file transfers certain files over to a customers server. In the batch script there is some coding that copys the file and puts in in a local backup folder adn then sends the file. The program seems to skip that step in the batch file and just transfers the file. Is there any way for me to place a line of scrpit that will place a copy of the file in the local backup folder and then run the batch script?


here is the line of script I am currently using.
FTP Script
  1. LOGTO("C:\logs\transfer_log.txt")
  2. EXEC('IDT.bat "'.$BACKUP_source.$BACKtxt.'"  "'.$BACKUP_Dest.$BACKtxt.'"')
I think your EXEC line is wrong. Here's what I'd do:
FTP Script
  1. $mybatch="IDT.bat"
  2. EXEC('$mybatch." ".$BACKUP_source.$BACKtxt." ".$BACKUP_Dest.$BACKtxt')
Hi there,

jbarntt, I think that the quotes in the EXEC call that cfctech wrote are fine. I guess you thought that ScriptFTP replaces variable names with values, like php. In that case, it's not.

cfctech, could you post the complete script and the batch file? Remember to hide any private information.
This way we can understand exactly what you are trying to do and help you. Thanks.
Hi,

Sorry for providing wrong information to cfctech, shouldn't have offered advice after using ScriptFTP for only a few days :(

I'm using this code snippet for emailing an OPENHOST error and it works, (SendEmail is similar to Blat):

[ScriptFTP]$sendemail="c:\bat\sendemail.exe "
$from="-f abcd@fake.xyz "
$to="-t dgfh@fake.xyz "
$server="-s 192.168.100.2 "
$subject='-u "Customer ftp download failed" '
$body='-m "Unable to connect to server. Myscript.ftp script"'

EXEC($sendemail.$from.$to.$server.$subject.$body)
 [/ScriptFTP]

This works, but I guess I got it wrong for cfctech.

Apologies,

jbarntt
Hi jbarntt,

Don't worry for that. You can post anything you may find useful, even if it's wrong. I think that it's part of the purpose of the internet forums. Then, it comes other more experienced user, like me, and fixes the error.

[ScriptFTP]EXEC($sendemail.$from.$to.$server.$subject.$body)[/ScriptFTP]

This works because the dot is used to concatenate the content of the variables. In ScriptFTP you can use Tthe follwoing different things as a command parameter:
  • A variable (like $foo)
  • A text string enclosed between double quotes, for example "whatever sdfa". You can use any character inside the string except the double quotes, which marks the end of the text string.
  • A text string enclosed between simple quotes, for example 'whatever sdfa'.You can use any character inside the string except the single quote, which marks the end of the text string.
  • A combination of the above elements using an operator, for example the dot (.) to contatenate or a plus (+) to add the contents, if they are numerical.
  • Other things such as numbers or command names, not common. For example PRINT(GETDATE(FORMAT1)) or SLEEP(5)


I hope this clarify the topic.