Variables within ftp txt file, please help

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
alexxxis
Posts: 2
Joined: 28 Nov 2011 05:15

Variables within ftp txt file, please help

#1 Post by alexxxis » 28 Nov 2011 05:22

Hi. I know this might have been solved 100 times before, but i spent one hour trying to find the answer and failed. Please help me out or point me to an existing topic.
I`m trying to do an automatic backup through on an ftp server.

got 2 files

backup_ftp.bat

Code: Select all

@echo on
FTP -v -i -s:rel.txt


and rel.txt

Code: Select all

OPEN release
<user>
<password>
lcd d:\test
set folder=%date:~10,4%%date:~4,2%%date:~7,2%
mkdir Backup\Luna\%folder%
mkdir Backup\Luna\%folder%\Counter\
mkdir Backup\Luna\%folder%\ttp\
lcd D:\Servers\Counter\
cd mkdir Backkup\Luna\%folder%\Counter\
mput *.*
lcd C:\Program Files\Seapine\
mkdir Backup\Luna\%folder%\ttp\
mput *.*
binary
MPUT *.*
BYE


instead of creating a folder with the date, it`s creating a folder named %folder%. how can i make it work and use the system variables? am i missing something basic or just doing some noobish mistake? Thank you in advance.

aGerman
Expert
Posts: 4736
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Variables within ftp txt file, please help

#2 Post by aGerman » 28 Nov 2011 17:04

I'm not familiar with that FTP stuff. For that reason I normally avoid to reply to such topics. But in your case it's obvious why it doesn't work.

You have to strictly separate the following:
1. Batch files are interpreted by cmd.exe. The commands in a batch file have nothing to do with the commands for FTP (even if they have sometimes the same name or a similar behaviour).
2. FTP is a command line tool. It can be called from a batch file but it has nothing to do with batch(-language). That means the Windows FTP tool does not support variables, string manipulation or anything else you could do with a batch code.
3. A FTP text file (referred by ftp-option -s: and the file name) is only a simple text file that contains the FTP commands in the order how the FTP tool has to process them. It belongs clearly to the FTP tool. If it contains batch code then the FTP tool is neither able to interpret it nor to process it.

The solution for your problem could be that you could process the variables in your batch file and (over-)write the text file for your FTP call.
Untested (and I have no idea whether all the FTP commands are right):
*.bat

Code: Select all

@echo on
set folder=%date:~10,4%%date:~4,2%%date:~7,2%

>rel.txt (
  echo OPEN release
  echo MyUserName
  echo MyPassword
  echo lcd d:\test
  echo mkdir Backup\Luna\%folder%
  echo mkdir Backup\Luna\%folder%\Counter\
  echo mkdir Backup\Luna\%folder%\ttp\
  echo lcd D:\Servers\Counter\
  echo cd mkdir Backkup\Luna\%folder%\Counter\
  echo mput *.*
  echo lcd C:\Program Files\Seapine\
  echo mkdir Backup\Luna\%folder%\ttp\
  echo mput *.*
  echo binary
  echo MPUT *.*
  echo BYE
)

FTP -v -i -s:rel.txt

Regards
aGerman

alexxxis
Posts: 2
Joined: 28 Nov 2011 05:15

Re: Variables within ftp txt file, please help

#3 Post by alexxxis » 29 Nov 2011 01:16

Ok, i will test that right out. thank you

Post Reply