1

I'm trying to execute the following batch script to copy file from ftp to local directory. However, I'm only able to login to the ftp but can't get the rest (bold code) of the script to execute. The script hangs at ftp> prompt.

ftp -i -n -v ftp.domain.com
quote 'User'
quote 'Password'
**cd /iatest
mget * C:\local\directory
pause**

Can someone please help? Thank you.

Got it to work. A couple of items for newbies like me: You need to two scripts to execute the task as following:

Script 1 (scriptname.bat): To call the .bat script with your code to execute.

ftp -i -n -s:yourscript.bat

Script 2: Actual code you want to execute which in my case is to copy files from ftp to specific local directory.

open ftp.domain.com
user username
password
cd /ftpDirectoryYouNeedToCopyFrom
lcd C:\DirectoryYouWantToCopyInto
mget * 
bye

Here is a good reference: http://www.youtube.com/watch?v=2YJMcns0ILk

spSingh
  • 21
  • 1
  • 4

2 Answers2

1

Got it to work. A couple of items for newbies like me: You need to two scripts to execute the task as following:

To call the .bat script with your code to execute.

@ECHO off
:: scriptname.bat
ftp -i -n -s:yourscript.commands
pause

Script 2 (yourscript.commands) : Actual code you want to execute which in my case is to copy files from ftp to specific local directory.

open ftp.domain.com
user username
password
cd /ftpDirectoryYouNeedToCopyFrom
lcd C:\DirectoryYouWantToCopyInto
mget * 
bye

Here is a good reference: http://www.youtube.com/watch?v=2YJMcns0ILk

djangofan
  • 28,471
  • 61
  • 196
  • 289
spSingh
  • 21
  • 1
  • 4
0

There's a pretty good tutorial on looping through files and uploading them to FTP on Intelliadmin.

It quickly walks you trough the various steps involved and shortly explains the principles behind the FTP-command, and then amounts to this:

1- Set the name of our temp script

@set SCRIPT_NAME=FTP_SCRIPT.FTP

2- Generate our FTP Script

@echo open [host]> %SCRIPT_NAME%
@echo [username]>> %SCRIPT_NAME%
@echo [password]>> %SCRIPT_NAME%
@echo bin>> %SCRIPT_NAME%
@echo hash>> %SCRIPT_NAME%

3- Loop through each file that matches our wildcard

@for %%f in (*.log) do @echo put %%f>> %SCRIPT_NAME%

echo quit>> %SCRIPT_NAME%

@REM = Now call FTP with our generated script
@ftp -s:%SCRIPT_NAME%`

@REM = Delete our temp script file and we are done
@del %SCRIPT_NAME% /q

Source: http://www.intelliadmin.com/index.php/2010/04/ftp-files-from-a-batch-file/

Luke
  • 409
  • 3
  • 12