如何使用 ftp 将变量传递到批处理文件的 %0 部分?
How to pass a variable into %0 part of batch file with ftp?
我有一个批处理文件,我希望能够从命令行调用它,例如:
myBatch.bat testParam
那个批处理文件如下:
set sid=%1
C:\Windows\System32\ftp.exe -s:%0
goto done
open servername
username
password
get 'FilePath%sid%restoffilepath' targetPath\%sid%MyName.txt
bye
:done
但是,我似乎无法让 FilePath%sid%restoffilepath
部分正常工作 - 我相信这是因为 %0
将输入视为文字,但我不是 100% 确定。 %sid% 变量未展开。
在这种情况下,我基本上想让 FilePath%sid%restoffilepath
成为 FilePathtestParamrestoffilepath
。
仔细想想你在这里做什么 -- ftp.exe 正在读取文件。知道 %1 是什么的批处理脚本没有将数据提供给 ftp.exe.
您需要做的是将脚本输出到一个文件中,然后 运行 ftp 命令:
set sid=%1
echo open servername >> myftp.txt
echo username >> myftp.txt
echo password >> myftp.txt
echo get 'FilePath%sid%restoffilepath' targetPath\%sid%MyName.txt >> myftp.txt
echo bye >> myftp.txt
C:\Windows\System32\ftp.exe -s:myftp.txt
我有一个批处理文件,我希望能够从命令行调用它,例如:
myBatch.bat testParam
那个批处理文件如下:
set sid=%1
C:\Windows\System32\ftp.exe -s:%0
goto done
open servername
username
password
get 'FilePath%sid%restoffilepath' targetPath\%sid%MyName.txt
bye
:done
但是,我似乎无法让 FilePath%sid%restoffilepath
部分正常工作 - 我相信这是因为 %0
将输入视为文字,但我不是 100% 确定。 %sid% 变量未展开。
在这种情况下,我基本上想让 FilePath%sid%restoffilepath
成为 FilePathtestParamrestoffilepath
。
仔细想想你在这里做什么 -- ftp.exe 正在读取文件。知道 %1 是什么的批处理脚本没有将数据提供给 ftp.exe.
您需要做的是将脚本输出到一个文件中,然后 运行 ftp 命令:
set sid=%1
echo open servername >> myftp.txt
echo username >> myftp.txt
echo password >> myftp.txt
echo get 'FilePath%sid%restoffilepath' targetPath\%sid%MyName.txt >> myftp.txt
echo bye >> myftp.txt
C:\Windows\System32\ftp.exe -s:myftp.txt