在逃生批处理脚本字符 [英] Escape characters in batch scripts

查看:146
本文介绍了在逃生批处理脚本字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本来自动文件上传到远程服务器。问题是,我一直在考虑,密码是充满了这些杀人登录过程中的特殊字符。

I have the following script to automate uploading a file to a remote server. The problem is that the password I have been given is full of special characters which are killing the login process.

下面是变了一个版本的字符:

Here is a changed version of the characters:

J7〜]%放大器; X

j7~]%&X

当使用正常的FTP应用程序不存在的一个问题。我已经包裹在引号密码,也使用 ^ 来逃避百分比符号尝试。但是,这是行不通的。另外,我不能告诉的是,正在发送的实际的密码。

When using a normal FTP application there isn't a problem. I have wrapped the password in quotes and have also tried using a ^ to escape the percentage and ampersand. However, it doesn't work. Also, I can't tell what the actual password is that is being sent.

什么可能会错误或我怎么透露密码发送之前?

What could be going wrong or how do I reveal the password before it is sent?

:Source = http://www.howtogeek.com/howto/windows/how-to-automate-ftp-uploads-from-the-windows-command-line/

@echo off
echo user myloginname> ftpcmd.dat
echo mypassword>> ftpcmd.dat
echo bin>> ftpcmd.dat
echo put %1>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat myserver
del ftpcmd.dat

SOLUTION

如下所述,我用类型命令来查看实际上是什么在 ftpcmd.dat 。事实证明,通过大量的试验错误,并在您使用不同的转义字符不同的特殊字符转义字符阅读起来!

As mentioned below, I used the "type" command to see what was actually in the ftpcmd.dat. It turns out that, through a lot of trial an error and reading up on escape characters that you use different escape characters for different special characters!!!

有关的符号用符号,和百分比使用百分比。因此,考虑到我的密码:

For an ampersand use a caret, and for the percentage use a percentage. So, given my password:

J7〜]%放大器; X

j7~]%&X

所产生的密码是:

J7〜] %% ^&放大器; X

j7~]%%^&X

推荐答案

在你的情况,你可以简单地键入您的文件透露密码,删除该文件之前。

In your case you could simply type your file to reveal the password, just before you delete the file.

但它是更好地使用延迟扩展,因为那时的特殊字符失去其特殊的行为,甚至插入符号和百分号。

But it's better to use the delayed expansion, because then the special characters lose their "special" behaviour, even carets and percent signs.

@echo off
setlocal EnableDelayedExpansion
set /p passwd=Enter pwd
echo user myloginname> ftpcmd.dat
echo mypassword>> ftpcmd.dat
echo bin>> ftpcmd.dat
echo put !passwd! >> ftpcmd.dat
echo quit>> ftpcmd.dat
type ftpcmd.dat
ftp -n -s:ftpcmd.dat myserver

的第二个问题是ftp命令,其中该字符也需要转义。
也许(如玉萍写)反斜杠可以工作。
你可以把它的每一个字符之前,通过使用一个for循环

The second problem is the ftp command, where the characters also need escaping. Perhaps (like Vicky wrote) the backslash could work. You can place it before each single character, by using a for-loop

这篇关于在逃生批处理脚本字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆