views:

62

answers:

2

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

When using a normal ftp app 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.

Any tips on what could be going wrong or how to 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

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

the resulting password would be:

j7~]%%^&X

+1  A: 

FTP passwords are sent in plain text so installing something like Wireshark will allow you to see what is being sent.

I would expect you would need to prefix the special characters with backslash.

Vicky
Vicky ... cheers. I managed to see what was happening using jeb's suggestion, but that software looks interesting anyway so will be a useful tool to have. Thanks.
alj
+1  A: 

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 there "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

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

jeb
What I ended up doing here was using the "type" command to output the ftpcmd.dat file. That helped me see what was going on. Thanks for that.
alj