简体   繁体   English

用户名| Windows FTP命令行批处理中发生管道故障

[英]username with | pipe failing in windows FTP command line batch

When creating a batch file to process FTP commands, how do you enter the username when ftp/batch has an issue with the pipe. 创建批处理文件以处理FTP命令时,当ftp / batch管道出现问题时,如何输入用户名。

Note: The dots/periods in the host and username are intential. 注意:主机和用户名中的点/句点是整数。

Example : 范例

REM Connection information:
SET Server=my.server.com
SET UserName=my.server.com|my.username
SET Password=password


IF NOT EXIST "%TEMP%\FTPCommands" MD "%TEMP%\FTPCommands"
SET Commands="%TEMP%\FTPCommands\SendToFTP_commands.txt"


rem -- add username and password to commands file
ECHO %UserName%> %Commands%
ECHO %Password%>> %Commands%

FTP -d -i -s:%Commands% %Server%

The error : 错误

"'my.username' is not recognized as an internal or external command, operable program or batch file." “'my.username'不被识别为内部或外部命令,可操作程序或批处理文件。”

try this: 尝试这个:

@echo off &setlocal
SET "UserName=my.server.com|my.username"
SETLOCAL ENABLEDELAYEDEXPANSION
> "%Commands%" ECHO(!UserName! 
endlocal

Put the variable definition between double quotes and escape the pipe with a ^ : 将变量定义放在双引号之间,并使用^对管道进行转义:

set "UserName=my.server.com^|my.username"

Without the double quotes you'd need to escape the pipe twice: once when defining, and once when echoing the variable: 如果没有双引号,则需要两次对管道进行转义:一次在定义时,一次在回显变量时:

set UserName=my.server.com^^^|my.username"

^^ is an escaped ^ and ^| ^^是转义的^^| is an escaped | 是逃脱的| , so that you still have an escaped pipe when echoing the variable. ,这样在回显该变量时仍然会有一个转义的管道。

you can use ^| 您可以使用^ | to escape the | 逃脱 symbol. 符号。

updated to correct for the escape character as pointed out by ansgar Dos treats the | 更新以更正ansgar Dos指出的转义字符对待| as the pipe symbol and trys to pipe the output of one command as the input of another. 作为管道符号,并尝试通过管道将一个命令的输出作为另一个命令的输入。 Hence your error. 因此,您的错误。 Because the pipe symbol is there the batch file interpreter expects my.server.com to be one program, that you are trying to pipe its output to my.username. 因为管道符号在那里,所以批处理文件解释器希望my.server.com是一个程序,因此您试图将其输出管道到my.username。

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

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