2

Need to write batch script which copies file from FTP to local drive

I'm trying to achieve this using cmd command prompt

inside batch file

please help me or paste any thread.

I found the answer thanks a lot but,

I need to use 2files script.txt and batch.bat

which contains script.txt code:

open ftp.server.com username password cd folderpath/newfolder get file1.xml close bye 

and batch.bat code

ftp -v -i -s:script.txt echo done! 

But How can i do it using only .bat file so that I need only 1 file not 2 files

1 Answer 1

2

As a starting point:

  1. Perform a NSLOOKUP for the FTP site, e.g. nslookup ftp.microsoft.com make a note of the IP address
  2. Edit the LMHOSTS file (in %systemroot%\system32\drivers\etc)
  3. Add line MicrosoftFTP #PRE e.g. 207.46.133.140 MicrosoftFTP #PRE
  4. Save the file
  5. Open a CMD.EXE session. Enter command: nbtstat -R This purges and reloads the name table cache
  6. Type command: net view \MicrosoftFTP You should see information on the site
  7. Now map a drive (to share data) net use * \MicrosoftFTP\data /user:anonymous
  8. All done. It will pass a drive letter for the connection

The next step would be to make steps 1-4 automatic by scripting the commands and using file/string manipulation to update the hosts file if necessary.

With a drive mapped you can then presumably do a normal Xcopy from one drive to another.

Reference: http://answers.yahoo.com/question/index?qid=20080612073002AAruBR0

UPDATE In response to your edit:

In your main batch.bat file, dynamically create script.txt as follows:

@echo off @echo open ftp.server.com > script.txt @echo username >> script.txt @echo password >> script.txt @echo cd folderpath/newfolder >> script.txt @echo get file1.xml >> script.txt @echo close >> script.txt @echo bye >> script.txt 

Then do

ftp -v -i -s:script.txt 

Finally - to tidy-up, remove the temporary script.txt:

del script.txt 
Sign up to request clarification or add additional context in comments.

2 Comments

thanks a ton! but how can i do it in only .bat file i mean using only one file :)
Perfect, just need to lose any spaces preceding ">" otherwise the username and password will get an undesired extra space and the script fails.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.