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?
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.
Copies a local file to the remote computer using the current file transfer type. This command is the same as the ftp send command.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With