Solved

DOS - FTP Batch File - Prompt for User Password

Posted on 2008-10-03
15
9,364 Views
Last Modified: 2012-06-27
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
Comment
Question by:spbarrett
  • 7
  • 7
15 Comments
 
LVL 7

Expert Comment

by:myhc
Comment Utility
what is in file script.txt ??
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
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
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
myhc, I think that snippet is completely broken. I'd like to know where the asker saw it.
0
 

Author Comment

by:spbarrett
Comment Utility
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
 

Author Comment

by:spbarrett
Comment Utility
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
 

Author Comment

by:spbarrett
Comment Utility
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
 

Author Comment

by:spbarrett
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
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
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
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
 

Author Comment

by:spbarrett
Comment Utility
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
 
LVL 40

Accepted Solution

by:
RQuadling earned 500 total points
Comment Utility
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
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
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
 

Author Comment

by:spbarrett
Comment Utility
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
 

Author Closing Comment

by:spbarrett
Comment Utility
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
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now