Solved FTP using batch script

May 17, 2012 at 06:51:23
Specs: Windows 7
I want to FTP few zip files from windows batch script.
I need to login to ftp server using same batch script,
i.e open ftp server, give user name & password , FTP <myfile> , log off or close

See More: FTP using batch script

Report •


#1
May 17, 2012 at 08:02:36
I use expect for windows.

Hang up and live.


Report •

#2
May 17, 2012 at 09:29:14
Create a batch file like this:

dl_ftp.bat

---SNIP---
@echo off
ftp -i -s:ftpcmd.txt
---SNIP---


Create the answer file ftpcmd.txt like this:

ftpcmd.txt

---SNIP---
OPEN your_servers_ip_or_fqdn
username
password

binary

cd /folder_on_ftp_server
get filename.txt or mget files*.*

bye
---SNIP---


Here is an exampel for the answer file ftpcmd.txt:
---
OPEN 192.168.1.10
ftpuser
secret123

binary

cd /data/downloads
mget *.*

bye
---


Report •

#3
May 17, 2012 at 13:42:46
✔ Best Answer
Something like this, modify for your needs:

@echo off
if exist _.ftp del _.ftp >nul
(
echo open ftp.host.com
echo anonymous
echo anon@ftp.host.com
echo cd directory
echo bin
echo hash
echo prompt
echo put <myfile>
echo bye
) > _.ftp
ftp -s:_.ftp
del _.ftp >nul

Tony


Report •

Related Solutions

#4
May 18, 2012 at 11:41:53
Thanks for the reply, but did not get what exactly to do.Can you please elaborate.

Report •

#5
May 18, 2012 at 13:17:56
Replace echo whatever with echo your_command. Do this manually once and record every command you execute, then place all those commands into a .bat script preceded with an echo between the opening and closing parens. What I posted is an example of how to do it.

Tony


Report •

#6
May 21, 2012 at 00:26:05
Hi
Again thanks for your priceless time,
the command if exist _.ftp del _.ftp >nul is used for what and do i need to use it as it is?

Report •

#7
May 21, 2012 at 03:38:38
It checks for the existence of a file named _.ftp and if found, deletes it. It's not necessary but I like to use it.

Tony


Report •

#8
May 21, 2012 at 03:50:26
Thanks a lot. I have found answers for whatever i have posted on computing.net

Report •

#9
May 21, 2012 at 04:24:22
One more before we close this, If my requirement is to take all the .txt files (only .txt) files from a particular folder i,e put F:\temp\*.txt
Where temp is folder from where i want to ftp all the .txt files.

Report •

#10
May 21, 2012 at 05:12:32
mput F:\temp\*.txt

Tony


Report •

#11
May 23, 2012 at 00:39:40
Can you please explain the significance of "-i -s" in ==> ftp -i -s:ftpcmd.txt

Report •


Ask Question