是否可以将变量传递给Windows FTP脚本文件? [英] Is it possible to pass a variable into a Windows FTP script file?
问题描述
我有一个批处理脚本,它可以动态地创建一些文件,并根据时间,日期等生成具有一定随机文件名的四个文件。然后它需要通过FTP将该文件上传到服务器。
截至目前,我的.bat文件有一行,如ftp -s:ftp.txt。 Ftp.txt包含一些相当简单的FTP脚本文件:像这样的东西 -
open ftp.myserver.com
用户名
密码
放入filename1.dat
放入filename2.dat
放入filename3.dat
放入filename4.dat
我想要做的是传入需要上传的文件名,然后将put filename1.dat替换为put%file1% --where%file1%是传入的文件名变量。
这可能吗?任何人都知道如何去做?或者,我的整个方法是错误的? 解决方案
您可以使用bat文件随时生成ftp.txt文件。只需执行以下操作:
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
当然,现在您已经在bat文件中,您可以使用环境变量和其他内容来代替filenameX.dat了。
例如:
echo put%file1%>> ftp.txt
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?
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
这篇关于是否可以将变量传递给Windows FTP脚本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!