Link to home
Start Free TrialLog in
Avatar of spbarrett
spbarrett

asked on

DOS - FTP Batch File - Prompt for User Password

I am trying to get a FTP batch file to prompt the user for a login ID and password.  I found code on this site but I do not have much FTP experience and am having trouble applying it to my batch file successfully.  Any help is greatly appreciated!!  I am running Window XP - SP2.

Steve


SAMPLE FOUND ON SITE.  MY BATCH FILE FOLLOWS.....
 
set script=c:\script.txt
open 1.1.1.1>echo %script%
set /p username=Enter username:
echo %username%>>echo %script%
set /p password=Enter password:
echo %password%>>echo %script%
prompt off>>echo %script%
mput *.*>>echo %script%
bye>>echo %script%
ftp -s:c:\script.txt
 
MY BATCH FILE......
 
ftp -ns:TNDMDownloads.txt 171.186.195.22 >> "C:\Documents and Settings\nbk25ym\My Documents\Exceptions\Model\FTP Script\logs\TNDMDownload.log"
 
MY SCRIPT......
 
user nbkk3c4 korr01ie
 
ascii
;  Temp for Deposit Products Demo GL Trans is posted trans
get 'TNDM.DEPPROD.GLBAL.DOWNLOAD' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLBALS_DEPPROD.tab"
get 'TNDM.DEPPROD.OPENITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_DEPPROD.tab"
get 'TNDM.DEPPROD.GLTRANS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLTrans_DEPPROD.tab"
get 'TNDM.DEPPROD.ALL.SUMBAL' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_AllSum.tab"
get 'TNDM.DEPPROD.AGEDITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\AppBal\IRC Database\Download Files\IRC_Raw_Data.csv"
quit

Open in new window

Avatar of myhc
myhc

what is in file script.txt ??
Read the REM comments in the snippet and give it a go.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
 
REM Define where the temp FTP script goes
SET FTP_Script=%TEMP%\FTP_Script.txt
 
REM Get username and password.
SET /P Username=Enter username:
SET /P Password=Enter password:
 
REM Build FTP Script using the username and password retrieved earlier,
REM along with the FTP commands for the file transfer.
ECHO OPEN 171.186.195.22>%FTP_Script%
ECHO USER %Username%>>%FTP_Script%
ECHO %Password%>>%FTP_Script%
ECHO prompt off>>%FTP_Script%
ECHO ascii>>%FTP_Script%
ECHO get 'TNDM.DEPPROD.GLBAL.DOWNLOAD' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLBALS_DEPPROD.tab">>%FTP_Script%
ECHO get 'TNDM.DEPPROD.OPENITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_DEPPROD.tab">>%FTP_Script%
ECHO get 'TNDM.DEPPROD.GLTRANS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLTrans_DEPPROD.tab">>%FTP_Script%
ECHO get 'TNDM.DEPPROD.ALL.SUMBAL' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_AllSum.tab">>%FTP_Script%
ECHO get 'TNDM.DEPPROD.AGEDITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\AppBal\IRC Database\Download Files\IRC_Raw_Data.csv">>%FTP_Script%
ECHO bye>>%FTP_Script%
 
REM Run the FTP script
FTP -n -s:%FTP_Script%>> "C:\Documents and Settings\nbk25ym\My Documents\Exceptions\Model\FTP Script\logs\TNDMDownload.log"
 
REM Tidy up.
DEL %FTP_Script%

Open in new window

myhc, I think that snippet is completely broken. I'd like to know where the asker saw it.
Avatar of spbarrett

ASKER

I found the code snippet on this site when I searched for FTP Script prompt user password.  I will give your code a try RQuading.  I truly appreciate it.
To confirm, I should put your code into the Script that the batch file calls, correct?  Apologies for the probably obvious question, but I am a true novice in DOS.
RQuadling, I placed the code you supplied in the script called on by my batch file and it did not work.  I get a blinking prompt in DOS but nothing seems to be happening.  
I also tried running the code as the batch file.  I am prompted for a user name and password but as soon as I hit enter after the password, the DOS window closes.  Any suggestions?
The batch file I supplied is complete. Assuming the IP address and all the locations you have are accurate.

I'll enhance the script with some debugging messages...
Here is the same script with more messages and debugging reporting.

Assuming the IP address are correct and all the paths you have are correct, then you should be able to run this straight away.



@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
 
REM Define where the temp FTP script goes
SET FTP_Script=%TEMP%\FTP_Script.txt
 
 
REM -- DEBUG --
ECHO We are going to create the FTP Script in %FTP_Script%
REM -- DEBUG --
 
 
REM -- DEBUG --
ECHO Our next step is to get the Username and password we need.
ECHO Simply type in the username and password when prompted and press [ENTER]
REM -- DEBUG --
 
 
REM Get username and password.
SET /P Username=Enter username:
SET /P Password=Enter password:
 
 
REM -- DEBUG --
ECHO The username you entered was '%Username%' and the password was '%Password%'.
REM -- DEBUG --
 
 
REM -- DEBUG --
ECHO We are now going to construct the FTP script using the supplied name and password and put it into the previously defined location.
REM -- DEBUG --
 
 
REM Build FTP Script using the username and password retrieved earlier,
REM along with the FTP commands for the file transfer.
ECHO OPEN 171.186.195.22>%FTP_Script%
ECHO USER %Username%>>%FTP_Script%
ECHO %Password%>>%FTP_Script%
ECHO prompt off>>%FTP_Script%
ECHO ascii>>%FTP_Script%
ECHO get 'TNDM.DEPPROD.GLBAL.DOWNLOAD' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLBALS_DEPPROD.tab">>%FTP_Script%
ECHO get 'TNDM.DEPPROD.OPENITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_DEPPROD.tab">>%FTP_Script%
ECHO get 'TNDM.DEPPROD.GLTRANS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLTrans_DEPPROD.tab">>%FTP_Script%
ECHO get 'TNDM.DEPPROD.ALL.SUMBAL' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_AllSum.tab">>%FTP_Script%
ECHO get 'TNDM.DEPPROD.AGEDITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\AppBal\IRC Database\Download Files\IRC_Raw_Data.csv">>%FTP_Script%
ECHO bye>>%FTP_Script%
 
 
REM -- DEBUG --
ECHO We have now built the FTP script. Here is it ...
TYPE %FTP_Script%
PAUSE
REM -- DEBUG --
 
 
REM -- DEBUG--
ECHO We are now going to run the FTP command with the supplied script and all the output of this process will be stored in a log file.
REM -- DEBUG --
 
 
REM Run the FTP script
FTP -n -s:%FTP_Script%>> "C:\Documents and Settings\nbk25ym\My Documents\Exceptions\Model\FTP Script\logs\TNDMDownload.log"
 
 
REM -- DEBUG --
ECHO We have now completed the FTP process and here is the log file that was produced. If there are any errors, please let us know.
TYPE "C:\Documents and Settings\nbk25ym\My Documents\Exceptions\Model\FTP Script\logs\TNDMDownload.log"
PAUSE
REM -- DEBUG --
 
 
REM -- DEBUG --
ECHO Now that the FTP process has finished, we need to remove the FTP script as it contains username and password details.
REM -- DEBUG --
 
 
REM Tidy up.
DEL %FTP_Script%
 
 
REM -- DEBUG --
ECHO We are done.
REM -- DEBUG --

Open in new window

RQuadling, I truly appreciate your efforts but I am not having success.  I ran the new batch file you produced.  The error I receive is "The system cannot find the path specified.".  I double checked the paths and even copied and pasted the paths from your script to my original script without a password prompt.  My original script worked fine so I am positive it is not a path issue.  One alternative thought, do you know of a way to save the script text you generate in the batch file as a .txt file?  Then I can use my original batch file to open it.  Thanks again for everyting.  Steve
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And this is the output of that script.

I've used the file names and the FTP server IP you supplied.

Please can you provide the output YOU get. It is important you supply it as is, though you can edit the username/password, but don't just delete the line, EDIT it so that just the name and password are garbage.

C:\EE>doftp
06/10/2008 20:51:28.46 We are going to create the FTP Script in :
06/10/2008 20:51:28.46 C:\DOCUME~1\Richard\LOCALS~1\Temp\FTP_Script.txt
 
06/10/2008 20:51:28.46 The FTP communication will be stored in :
06/10/2008 20:51:28.46 C:\DOCUME~1\Richard\LOCALS~1\Temp\FTP_Script.txt.LOG
 
 
06/10/2008 20:51:28.46 Our next step is to get the Username and password we need.
06/10/2008 20:51:28.47 Simply type in the username and password when prompted
06/10/2008 20:51:28.47 and press [ENTER]
Enter username:Richard
Enter password:Quadling
 
 
06/10/2008 20:51:33.77 The username you entered was 'Richard' and the
06/10/2008 20:51:33.77 password was 'Quadling'.
 
 
06/10/2008 20:51:33.78 We are now going to construct the FTP script using
06/10/2008 20:51:33.78 the supplied name and password and put it into the
06/10/2008 20:51:33.78 previously defined location.
 
 
06/10/2008 20:51:33.80 We have now built the FTP script. Here is it ...
 
 
OPEN 171.186.195.22
USER Richard
Quadling
prompt off
ascii
get 'TNDM.DEPPROD.GLBAL.DOWNLOAD' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLBALS_DEPPROD.tab"
get 'TNDM.DEPPROD.OPENITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_DEPPROD.tab"
get 'TNDM.DEPPROD.GLTRANS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLTrans_DEPPROD.tab"
get 'TNDM.DEPPROD.ALL.SUMBAL' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_AllSum.tab"
get 'TNDM.DEPPROD.AGEDITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\AppBal\IRC Database\Download Files\IRC_Raw_Data.csv"
bye
 
 
Press any key to continue . . .
 
 
06/10/2008 20:51:45.57 We are now going to run the FTP command with the
06/10/2008 20:51:45.57 supplied script and all the output of this process
06/10/2008 20:51:45.57 will be stored in a log file.
 
 
> ftp: connect :Unknown error number
 
 
06/10/2008 20:52:06.76 We have now completed the FTP process and here
06/10/2008 20:52:06.76 is the log file that was produced. If there are
06/10/2008 20:52:06.76 any errors, please let us know.
 
 
ftp> ftp> OPEN 171.186.195.22
Not connected.
ftp> USER Richard
Invalid command.
ftp> Quadling
Interactive mode Off .
ftp> prompt off
Not connected.
ftp> ascii
Not connected.
ftp> get 'TNDM.DEPPROD.GLBAL.DOWNLOAD' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLBALS_DEPPROD.tab"
Not connected.
ftp> get 'TNDM.DEPPROD.OPENITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_DEPPROD.tab"
Not connected.
ftp> get 'TNDM.DEPPROD.GLTRANS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLTrans_DEPPROD.tab"
Not connected.
ftp> get 'TNDM.DEPPROD.ALL.SUMBAL' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_AllSum.tab"
Not connected.
ftp> get 'TNDM.DEPPROD.AGEDITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\AppBal\IRC Database\Download Files\IRC_Raw_Data.csv"
bye
ftp> ftp> OPEN 171.186.195.22
Not connected.
ftp> USER Richard
Invalid command.
ftp> Quadling
Interactive mode Off .
ftp> prompt off
Not connected.
ftp> ascii
Not connected.
ftp> get 'TNDM.DEPPROD.GLBAL.DOWNLOAD' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLBALS_DEPPROD.tab"
Not connected.
ftp> get 'TNDM.DEPPROD.OPENITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_DEPPROD.tab"
Not connected.
ftp> get 'TNDM.DEPPROD.GLTRANS' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLTrans_DEPPROD.tab"
Not connected.
ftp> get 'TNDM.DEPPROD.ALL.SUMBAL' "\\ks1020-dal00n2\r_and_i\TDSCentral\Model Exceptions\Recon\Download Files\Mainframe Batch Files\GLRECON_AllSum.tab"
Not connected.
ftp> get 'TNDM.DEPPROD.AGEDITMS' "\\ks1020-dal00n2\r_and_i\TDSCentral\AppBal\IRC Database\Download Files\IRC_Raw_Data.csv"
bye
 
 
Press any key to continue . . .
 
 
06/10/2008 20:52:13.69 Now that the FTP process has finished, we need to
06/10/2008 20:52:13.69 remove the FTP script as it contains username and
06/10/2008 20:52:13.69 password details.
 
 
 
 
06/10/2008 20:52:13.70 We are done.

Open in new window

IT WORKED!!  Whatever you added did the trick.  I stripped out the debugging code to clean it up and it is working like a charm!!  I cannot thank you enough for your time, intellect, and perseverance.  You have made my day!!  Thank you!
I cannot thank you enough for all of your help.  Thank you for your patience with me through the process and for your perseverance.  I truly appreciate your help!!  Thanks again.  Steve
The only thing I really changed was the location of the log file produced by running FTP.

But, glad to have got it working for you.