All,
Background:
I have a batch script that has an sftp command in it that's supposed
to log in to a server and pull a file. The set of commands to be
executed on the server are consolidated in a command file and this
file is used in the sftp command as the input parameter.
Issue:
The file to be pulled has a dynamic timestamp on it that keeps changing with every new file. I calculate that timestamp in the main
script and store it in a variable. But in order to pull the correct file, I need to pass this variable to the command file so that the
actual filename on the server could be determined on run time. But the compiler fails to recognize this variable(%ts%) in the command file.
Below is the putty sftp command in the main batch script:
psftp user@server -pw "password" -batch -be -b C:\Scripts\Inbound.txt
The contents of C:\Scripts\Inbound.txt are as below:
cd test
lcd C:\data\in\
get goods_receipt.-%ts%.txt
close
quit
The above usage of %ts% needs to be fixed. Any ideas or comments would be helpful.
Thanks in advance.
Batch programming help - variables
Moderator: DosItHelp
Re: Batch programming help - variables
you have to make the batch create the Inbound file, so it can pass the value of "%ts%" to the file when it reads it.
So your main batch do these steps:
1) calculate the time stamp.
2) Create the Inbound file, and pass the dynamic stamp while creating it.
3) Run the SFTP command.
The 2nd Step this is how it's should be done: ( add this to your batch before running the sftp command )
This code will overwrite any existing file, and make sure the path exist, it won't create the folder Scripts if it doesn't exist.
So your main batch do these steps:
1) calculate the time stamp.
2) Create the Inbound file, and pass the dynamic stamp while creating it.
3) Run the SFTP command.
The 2nd Step this is how it's should be done: ( add this to your batch before running the sftp command )
Code: Select all
(
ECHO cd test
ECHO lcd C:\data\in\
ECHO get goods_receipt.-%ts%.txt
ECHO close
ECHO quit
)>"C:\Scripts\Inbound.txt"
Re: Batch programming help - variables
I agree with this solution abc. I was able to make my script work using this method. But I am more interested in knowing how the parameter passing works in such a scenario.
Re: Batch programming help - variables
You can only pass variables from batch files while the batch file creates the inbound file, as the sftp command is the one who reads the file, so it can't modify or replace any words inside it, even if the batch reading the file it won't unless you code it in a way the make it do that.
Re: Batch programming help - variables
Okay, I understand now. Thanks so much for your prompt assistance. 
Regards,
Sheldor

Regards,
Sheldor