How to read an output of filezilla-server-crypt command with a cmd/batch script?

169 Views Asked by At

in order to migrate an FTP database to an SFTP database, I need to create a script that modifies a xml file.

For the user, I need to encrypt the password.

I've found that a file called filezilla-server-crypt can be used in a cmd to encrypt a password.

However, when this command is used, the return is automatic.

For my script, I therefore need to read the result of the command in order to recover the encrypted password and the salt.

Here is my code in the cmd script:

net use a : \\Test$
for /f "tokens=*" %%a in ('a:\filezilla-server-crypt test echo test') do set "line=%%a"
echo line :
echo %line%
net use a : /delete

Even if I use start a:\filezilla-server-crypt test echo test the %line% variable is empty.

Do you have an idea how to retrieve the result?

2

There are 2 best solutions below

0
UrbanDae On BEST ANSWER

If the answer above doesn't work, you can use this technique:

SET /p supplierMail=Enter the supplier's e-mail address :

SET /p=%supplierPswd%<nul >> C:\temp.txt

FOR /f "delims=" %%G IN ('A:\filezilla-server-crypt.exe test ^< C:\temp.txt') DO SET "line=%%G"

DEL C:\temp.txt

This method use a temporary file which contains the password in order to implement it (a variable can't be implement with < that's why I use a file) in the window generated by this command :

A:\filezilla-server-crypt.exe test

The difference whith the other method is that the other method delete the error messages with this: 2^>NUL so for all situations, the code will return a value even if it is false.

0
Compo On

I'd assume so by echo test that you are trying to submit your password via stdIn and have just guessed how to do it.

Before you attempt to create a commandline using another one within it, you should first test that inner command. If you open a Command Prompt, map your A: drive, and type a:\filezilla-server-crypt test echo test and press the ENTER key, it does not work by automatically inputting the password.

Your question therefore should have been how do I automatically supply my password in filezilla-server-crypt, post v1.3.

My answer would have been:

(Echo test) | A:\filezilla-server-crypt.exe test

To perform the task of capturing the output from that command as a variable, here's a complete rewritten example, (with changes mentioned within the comment section).

@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

PushD "\\Test$" 2>NUL || Exit /B

Set "line="
For /F "Delims=" %%G In ('(Echo test^) ^| filezilla-server-crypt.exe test
 2^>NUL') Do Set "line=%%G"
If Not Defined line Exit /B
Echo %line%
Pause

PopD

EndLocal
GoTo :EOF

In your particular case, you could probably do it a little better by keeping the drive mapping within the for loop like this:

For /F "Delims=" %%G In ('PushD "\\Test$" ^&^& ((Echo test^) ^|
 filezilla-server-crypt.exe test ^& PopD^) 2^>NUL') Do Set "line=%%G"

Please note that this answer was designed for the user and password strings you submitted, you may have to make changes to this code if either of those use non alphanumeric characters.