Solved

# FTP with Batch File

Posted on 2012-12-27
1,276 Views
Last Modified: 2012-12-27
From a Windows XP computer, I am looking to create a batch file to automate an FTP Login and FTP copy of multiple files at one time up to an FTP Server.
I had posted this issue before a while back but didn't get around to testing the solutions offered.
Below is the link to one of the solutions offered.   I tried the open command and got an error.  The other option uses a .scr file along with the FTP -S and FTP -N
Any ideas on how I an acomplish all within the .bat file and not have to call a .scr file?     Thanks.

http://support.microsoft.com/kb/96269

open hostname.com
user
guest
guest

It also talks about ftp -s:test.scr
and using ftp -n option as well.
0
Question by:fjkaykr11
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 7
• 6
• 3
• +1
18 Comments

LVL 22

Accepted Solution

mcsween earned 245 total points
ID: 38724818
Create a text file with your commands in it; the first two lines should be as follows, the rest are just a sample
USER userID
PWD password
GET \path\to\somefile.txt %userprofile%\Desktop\somefile.txt
PUT "c:\program files\somefile.txt" \path\to\somefile.txt
BYE

Where UserID and password are your actual userid and password.  Then just call
ftp -n -s:somecommandfile.txt

Here is a list of the methods the Microsoft FTP command supports
http://technet.microsoft.com/en-us/library/bb490684.aspx
0

LVL 3

Author Comment

ID: 38724834
@mcsween thanks for the reply.
For the ftp -n -s:file.txt where do I specify the hostname of the ftp server ?
0

LVL 13

Assisted Solution

Jeff Darling earned 190 total points
ID: 38724837
If your open command doesn't work, there are some possible reasons for that.

1. Is the FTP server is down?  Try connecting to the FTP manually.
2. Is your DNS resolving?  Try a nslookup command to whatever your hostname is.  If that doesn't work, then try by IP number instead of hostname.
3. Do you have a firewall blocking you?  You will need to setup a firewall rule to allow you an exception.

I've used the ftp -s option for years. it works well, but each put command is done in series, not parallel within a script.

If you want to open multiple connections so that you can do parallel transfers, you can use a batch program like this.

Create a command prompt batch file named DO.BAT
start ftp -s:test1.scr
start ftp -s:test2.scr
start ftp -s:test3.scr
start ftp -s:test4.scr

Your test1.scr will look something like you have posted from the microsoft site, but you will need the username and password.
open hostname.com
username
password
binary
put file1.zip
quit

Each of the scr files will have a single put command.  I would recommend limiting the number of parallel transfers.   remember that you need to code binary for any binary files like PKZIP files, excel files, etcetera.

When you run the DO.BAT the system will automatically open a new command window for each transfer and they will run in parallel.
0

LVL 3

Author Comment

ID: 38724889
@jeffld To answer your questions about DNS and Firewall. That is not the issue I can connect fine from a command prompt using FTP IP Address and then typing in the user and password.   I am confused about your parallel transfers .scr reference?  Are you saying I can't do the other method, ftp -n -s:somecommandfile.txt  in Windows?
0

LVL 22

Assisted Solution

mcsween earned 245 total points
ID: 38724931
You can also call the command like this

ftp -n -s:somecommandfile.txt ftp.somehost.com

0

LVL 13

Assisted Solution

Jeff Darling earned 190 total points
ID: 38724935
you can put all your transfers into one script file, but they will run one after the other.  In series.

In your question you specifically asked for "FTP copy of multiple files at one time up to an FTP Server".

If you don't care if your files run in series, then you can just use one script file.

open hostname.com
username
password
binary
put file1.zip
put file2.zip
put file3.zip
put file4.zip
quit


I've never used the -n parameter.

If you want to see the parameters for command line ftp just type ftp --help

C:\sample>ftp --help

Transfers files to and from a computer running an FTP server service
(sometimes called a daemon). Ftp can be used interactively.

FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [-A] [host]

-v             Suppresses display of remote server responses.
-n             Suppresses auto-login upon initial connection.
-i             Turns off interactive prompting during multiple file
transfers.
-d             Enables debugging.
-g             Disables filename globbing (see GLOB command).
-s:filename    Specifies a text file containing FTP commands; the
commands will automatically run after FTP starts.
-a             Use any local interface when binding data connection.
-A             login as anonymous.
-w:buffersize  Overrides the default transfer buffer size of 4096.
host           Specifies the host name or IP address of the remote
host to connect to.

Notes:
- mget and mput commands take y/n/q for yes/no/quit.
- Use Control-C to abort commands.

0

LVL 3

Author Comment

ID: 38724966
@jeffld the open command doesn't work on my system, I get an error not recognized. I am aware of the help option. thanks.

@mcsween when I tried to follow your steps, I get an error invalid command for the login username, any ideas?
0

LVL 13

Assisted Solution

Jeff Darling earned 190 total points
ID: 38725002
Does the open work manually?

Here is an example where I connect manually and login using anonymous login.

I'm using ftp.microsoft.com as an example

C:\sample>ftp
ftp> open ftp.microsoft.com
Connected to ftp.microsoft.akadns.net.
220 Microsoft FTP Service
User (ftp.microsoft.akadns.net:(none)): anonymous
331 Anonymous access allowed, send identity (e-mail name) as password.
Password:
230-Welcome to FTP.MICROSOFT.COM. Also visit http://www.microsoft.com/downloads.
230 User logged in.
ftp>


Here it is using a script

here is the script.  with anonymous login, anonymous is the user and any email address is the password.
open ftp.microsoft.com
anonymous
test@yahoo.com
quit


here is the sample run
C:\sample>ftp -s:myscript.txt
ftp> open ftp.microsoft.com
Connected to ftp.microsoft.akadns.net.
220 Microsoft FTP Service
User (ftp.microsoft.akadns.net:(none)):
331 Anonymous access allowed, send identity (e-mail name) as password.
230-Welcome to FTP.MICROSOFT.COM. Also visit http://www.microsoft.com/downloads.
230 User logged in.
ftp> quit
221 Thank you for using Microsoft products.

0

LVL 43

Assisted Solution

Steve Knight earned 65 total points
ID: 38725012
Have a look at my ftp scripts here:

http://scripts.dragon-it.co.uk/links/batch-ftp-scripting

That explains some of the different ways it needs, I prefer this method generally which keeps it all in one file like you wanted.  You might need username password  all one one line instead as:

echo user username password

and use the cd / lcd lines as you wish or just remove them if not needed.

hth

Steve

@echo off
(echo open 110.110.110.110
echo user username
echo password
echo cd /destination/path
echo lcd C:\sourcepath
echo bin
echo put file1.zip
echo put file2.zip
echo put file3.zip
echo put file4.zip
echo quit
) | ftp -n -i

0

LVL 3

Author Comment

ID: 38725022
@jeffld. I think I am missing something here.
If I type in open ftpserver ip I get an error.
Don't I need to type FTP first?
like
FTP Open ip address ?
If I do this manually and I type FTP, then I get an FTP prompt, then I can type in
Open FTP Server ok.  But I still am lost at how to accomplish this within a Batch File.
0

LVL 13

Assisted Solution

Jeff Darling earned 190 total points
ID: 38725055
Once you are at the FTP prompt, then all you do is send FTP commands.

if you type ftp and the command prompt and press enter, that gets you to the ftp prompt., then you can issue ftp commands.

The nice thing about -s parameter using a script file is that you can just have all your ftp commands, the put or get commands in a text file and it executes.
0

LVL 3

Author Comment

ID: 38725056
@dragon-it thanks for the info.  When I tried your method the command prompt pops up and is stuck waiting for an input of the password (like below)

password:
0

LVL 13

Assisted Solution

Jeff Darling earned 190 total points
ID: 38725069
what is the error you get?

Here are two of the common errors I've seen.

connection refused
unknown host somehost.com

0

LVL 43

Assisted Solution

Steve Knight earned 65 total points
ID: 38725071
Ok, did you try the methods shown, i.e.

echo user username
echo user username password

Steve
0

LVL 13

Assisted Solution

Jeff Darling earned 190 total points
ID: 38725080
@dragon-it  That piping did not work for me either.  I get the same result of the prompt of the password.

0

LVL 13

Assisted Solution

Jeff Darling earned 190 total points
ID: 38725088
@dragon-it it works if I put the password on the same line like this.

echo user username password
0

LVL 3

Author Closing Comment

ID: 38725149
I was able to get this done finally with adjusting @mcsween's method (see below for what worked).  Thanks.
FTP Batch File Command: ftp -i -n -s:file.txt FTPServerIP

file.txt file info
username
username
password
cd UploadDirectory
mput *
quit
0

LVL 43

Expert Comment

ID: 38725161
Yes, some servers work with one, some the other but they all should work with one of them.

Steve
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
###### Suggested Courses
Course of the Month8 days, 3 hours left to enroll

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

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