Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pass a variable into a Windows FTP script file?

I have a batch script that dynamically creates some files and generates four files with somewhat random filenames based on the time, date, etc. It then needs to upload that file to a server via FTP.

As of right now, my .bat file has a line like "ftp -s:ftp.txt". Ftp.txt contains some fairly straightforward FTP script stuff: something like this--

open ftp.myserver.com
username
password
put filename1.dat
put filename2.dat
put filename3.dat
put filename4.dat

What I'd like to do is pass in the filenames that need to be uploaded and then replace the "put filename1.dat" with "put %file1%"--where %file1% is the filename variable being passed in.

Is this possible? Anybody know how to do it? Or is my whole approach wrong?

like image 687
SuperNES Avatar asked Mar 02 '11 16:03

SuperNES


People also ask

How do I automate an ftp file transfer?

Setting up automatic FTP scheduling is as easy as right-clicking on the folder or directory you want to schedule, and clicking Schedule. In the Task Scheduler section you'll be able to name the task, and set a date and time for the transfer to occur.

What does put command do in ftp?

Copies a local file to the remote computer using the current file transfer type. This command is the same as the ftp send command.

What is LCD command in ftp?

to request a list of all available FTP commands. lcd. to change directory on your local machine (same as UNIX cd) ls. to list the names of the files in the current remote directory.


1 Answers

You could generate the ftp.txt file on the fly with your bat file. Simply do something like :

echo ftp.myserver.com>ftp.txt
echo username>>ftp.txt
echo password>>ftp.txt
echo put filename1.dat>>ftp.txt
echo put filename2.dat>>ftp.txt
echo put filename3.dat>>ftp.txt
echo put filename4.dat>>ftp.txt
ftp -s:ftp.txt

Of course now that you are in the bat file you can use environment variables and other stuff in place of "filenameX.dat"

For example :

echo put %file1% >>ftp.txt
like image 102
Sébastien Nussbaumer Avatar answered Sep 19 '22 19:09

Sébastien Nussbaumer