[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9868
  • Last Modified:

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

0
spbarrett
Asked:
spbarrett
  • 7
  • 7
1 Solution
 
myhcCommented:
what is in file script.txt ??
0
 
Richard QuadlingSenior Software DeverloperCommented:
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

0
 
Richard QuadlingSenior Software DeverloperCommented:
myhc, I think that snippet is completely broken. I'd like to know where the asker saw it.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
spbarrettAuthor Commented:
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.
0
 
spbarrettAuthor Commented:
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.
0
 
spbarrettAuthor Commented:
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.  
0
 
spbarrettAuthor Commented:
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?
0
 
Richard QuadlingSenior Software DeverloperCommented:
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...
0
 
Richard QuadlingSenior Software DeverloperCommented:
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

0
 
spbarrettAuthor Commented:
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
0
 
Richard QuadlingSenior Software DeverloperCommented:
Can you run my script and copy ALL the output you have to here.

I've amended the program even further to output some times. As you run it, take your time. Wait a few seconds for each step so that the log file looks interesting.

So, 2 posts.

The first is an amendment to use a different location for the log file. The message you are getting suggests that "C:\Documents and Settings\nbk25ym\My Documents\Exceptions\Model\FTP Script\logs\TNDMDownload.log" is an invalid location. So the FTP command cannot write to the location and there is no log file to read.

The script below uses the name/location of the FTP script and a little more debugging.



@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
 
REM Define where the temp FTP script goes
SET FTP_Script=%TEMP%\FTP_Script.txt
 
 
REM -- DEBUG --
ECHO %DATE% %TIME% We are going to create the FTP Script in :
ECHO %DATE% %TIME% %FTP_Script%
ECHO.
ECHO %DATE% %TIME% The FTP communication will be stored in :
ECHO %DATE% %TIME% %FTP_Script%.LOG
ECHO.
ECHO.
REM -- DEBUG --
 
 
REM -- DEBUG --
ECHO %DATE% %TIME% Our next step is to get the Username and password we need.
ECHO %DATE% %TIME% Simply type in the username and password when prompted
ECHO %DATE% %TIME% and press [ENTER]
REM -- DEBUG --
 
 
REM Get username and password.
SET /P Username=Enter username:
SET /P Password=Enter password:
 
 
REM -- DEBUG --
ECHO.
ECHO.
ECHO %DATE% %TIME% The username you entered was '%Username%' and the
ECHO %DATE% %TIME% password was '%Password%'.
ECHO.
ECHO.
REM -- DEBUG --
 
 
REM -- DEBUG --
ECHO %DATE% %TIME% We are now going to construct the FTP script using
ECHO %DATE% %TIME% the supplied name and password and put it into the
ECHO %DATE% %TIME% previously defined location.
ECHO.
ECHO.
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 %DATE% %TIME% We have now built the FTP script. Here is it ...
ECHO.
ECHO.
TYPE %FTP_Script%
ECHO.
ECHO.
PAUSE
REM -- DEBUG --
 
 
REM -- DEBUG--
ECHO.
ECHO.
ECHO %DATE% %TIME% We are now going to run the FTP command with the
ECHO %DATE% %TIME% supplied script and all the output of this process
ECHO %DATE% %TIME% will be stored in a log file.
ECHO.
ECHO.
REM -- DEBUG --
 
 
REM Run the FTP script
FTP -n -s:%FTP_Script%>> %FTP_Script%.LOG
 
 
REM -- DEBUG --
ECHO.
ECHO.
ECHO %DATE% %TIME% We have now completed the FTP process and here
ECHO %DATE% %TIME% is the log file that was produced. If there are
ECHO %DATE% %TIME% any errors, please let us know.
ECHO.
ECHO.
TYPE %FTP_Script%.LOG
ECHO.
ECHO.
PAUSE
REM -- DEBUG --
 
 
REM -- DEBUG --
ECHO.
ECHO.
ECHO %DATE% %TIME% Now that the FTP process has finished, we need to
ECHO %DATE% %TIME% remove the FTP script as it contains username and
ECHO %DATE% %TIME% password details.
ECHO.
ECHO.
REM -- DEBUG --
 
 
REM Tidy up.
DEL %FTP_Script%
 
 
REM -- DEBUG --
ECHO.
ECHO.
ECHO %DATE% %TIME% We are done.
ECHO.
ECHO.
REM -- DEBUG --

Open in new window

0
 
Richard QuadlingSenior Software DeverloperCommented:
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

0
 
spbarrettAuthor Commented:
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!
0
 
spbarrettAuthor Commented:
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
0
 
Richard QuadlingSenior Software DeverloperCommented:
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.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now