简体   繁体   English

如何使用ftp将变量传递到批处理文件的%0部分?

[英]How to pass a variable into %0 part of batch file with ftp?

I have a batch file I want to be able to call from the command line like: 我有一个批处理文件,希望能够从命令行调用,例如:

myBatch.bat testParam

That batch file is the following: 该批处理文件如下:

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

However, I cannot seem to get the FilePath%sid%restoffilepath part to work right - I believe it is because the %0 is treating the input as literal, but I'm not 100% sure. 但是,我似乎无法使FilePath%sid%restoffilepath部分正常工作-我相信这是因为%0将输入视为文字,但是我不确定100%。 The %sid% variable is not expanded. %sid%变量不会扩展。

I basically want to have FilePath%sid%restoffilepath be FilePathtestParamrestoffilepath in this case. 在这种情况下,我基本上想让FilePath%sid%restoffilepath成为FilePathtestParamrestoffilepath

Think carefully about what you are doing here--the ftp.exe is reading the file. 请仔细考虑您在这里所做的事情-ftp.exe正在读取文件。 Your batch script, which knows what %1 is, is not feeding the data to ftp.exe. 您的批处理脚本知道%1是什么,它没有将数据提供给ftp.exe。

What you need to do is to shoot the script out to a file, and then run the ftp command: 您需要做的是将脚本发布到一个文件中,然后运行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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM