Wednesday, February 4, 2009

Batch script to change FTP password

Changing password for FTP users accounts requires entering FTP commands in command mode. This is usually to much for end users who need to change their FTP passwords by themselves. I wrote a batch file script to make the job easier. Save the content below in a .bat file and run it.

If it does not work again your FTP server, check the syntax of

literal SITE CHPW %old_password% %new_password%

Your FTP server may use a different syntax.

@echo off

echo This program changes password on ftp.domain.com.
echo.
SET /P username=Enter FTP Username:
SET /P old_password=Enter Old FTP Password:
SET /P new_password=Enter New FTP Password:
SET /P new_password2=Enter New FTP Password again:

If not %new_password%==%new_password2% goto bad

echo %username%> ftpcmd.txt
echo %old_password%>> ftpcmd.txt
echo literal SITE CHPW %old_password% %new_password%>> ftpcmd.txt
echo bye>> ftpcmd.txt
echo.
echo ************** System Message Begins ********************************
ftp -i -s:ftpcmd.txt ftp.domain.com
echo ************** System Message Ends **********************************
del ftpcmd.txt

echo.
echo From the System Message above, you can see whether the password has been
echo changed successfully or not. If successful, the new direct access URL is:
echo.
echo ftp://%username%:%new_password%@ftp.domain.com
echo.
echo NOTE:
echo To copy URL to clipboard: Right-click, Mark, select, enter.
echo.
echo.
echo This window will close.
pause
goto end

:bad
echo.
Echo New passwords dismatch.
echo.
echo This window will close.
pause

:end

No comments: