Question

FTP - How to FTP from batch, dos or vbscript

Asked by: elwayisgod

Hi,

I need to ftp a file from a unix server to a windows server via windows batch, dos or vbscript?

Windows Server: destserver
Unix Server: sourceserver
Filename on Unix Server: filename.txt
Location of source file on Unix server: /home/hyperion/filename.txt
Location of destination of file on Win Server: D:\CFM\filename.txt

Do I need anyother information?  Possible usernames and passwords?  The script needs to be run from the Windows server too.

Thanks

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-15 at 10:24:02ID24733699
Tags

FTP dos windows batch vbscript

Topics

File Transfer Protocol (FTP)

,

MS DOS

,

Windows Batch Scripting

Participating Experts
4
Points
235
Comments
38

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Opening up a batch file using vbscript
    Hello again, Yet another vbscript question: - I have a vbscript file which prompts the user to enter a location (eg. C:\Folder1\) into an inputbox. The location they enter is then added to a batch file. After the location is added to the batch file I'd like the script to au...
  2. Run a VBscript file from a batch file
    I need a syntax to run a VBScript file(.vbs) from a batch file(.bat) thanks
  3. Launch a batch file with VBScript
    All I am looking to do is have a VBScript dialog box that appears with some text and then two buttons side-by-side, each button will launch a different batch file and close the dialog box. Does anyone have something in mind?
  4. Call a batch file in VBSCRIPT
    Call a batch file in VBSCRIPT. The batch file is located on a server and I will be inserting it into all users logon script. The script is pushed out by GPOs so it has rights to connect to the server.
  5. Execute all batch files in a folder with vbscript
    I would simply like to write a vbscript file that executes all batch files within a folder.
  6. Batch to VBScript for Logon
    I am interested in using vbscript for my logon script in my domain instead of batch. Currently, I have four sites and in my current batch file logon script, there is a " CALL %LOGONSERVER%.bat" command in the script which will map drives specific to that location fo...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: celzo76Posted on 2009-09-15 at 10:32:29ID: 25337232

-- script.txt --

OPEN my.ftp.com
mylogin
mypassword
binary
lcd D:\CFM\
get /home/hyperion/filename.txt
BYE

--o--

and to run it from the windows box
ftp -i -s script.txt

 

by: netcmhPosted on 2009-09-15 at 10:34:40ID: 25337255

In it's simplest, from your destserver:

BAT File Code:

D:\
cd D:\CFM\filename.txt
ftp -s:ftpparams.txt
PAUSE

The ftpparams.txt File Code:

open sourceserver
user {userID}
{password}
cd /home/hyperion/
get filename.txt
bye

Of course edit the userID, password

 

by: dragon-itPosted on 2009-09-15 at 10:35:22ID: 25337262

You need a file along these lines:

Save the following as ftpscript.txt

open sourceserver
lcd D:\cfm
cd /home/hyperion
asc
get filename.txt
quit

then in a batch file:

@echo off
ftp -n -i -ss:ftpscript.txt

Steve

 

by: dragon-itPosted on 2009-09-15 at 10:42:04ID: 25337326

Not quite sure what was going on with my typing there.... and missed out the user/password, doh!  

 

by: QlemoPosted on 2009-09-15 at 10:53:15ID: 25337436

Don't like "two files approach". You can modify that (shown with the code of netcmh, mixed with the FTP options of dragon-it):

@echo off
( echo open sourceserver
 echo user {userID}
  echo {password}
 echo cd /home/hyperion/
 echo get filename.txt
 echo bye

) | ftp -n -i

 

by: dragon-itPosted on 2009-09-15 at 11:05:47ID: 25337536

Qlemo's way - I tend to do that way for my own scripts though it can make long scripts less clear.  In this case certainly seems a god plan.

 

by: QlemoPosted on 2009-09-15 at 11:06:58ID: 25337550

Agreed, not good for long FTP scripts. But allows for dynamic creation of commands :-)

 

by: elwayisgodPosted on 2009-09-15 at 12:11:16ID: 25338173

OK... As soon as they give me proper access to the server I can try these.  The username and password needs what access on the sourceserver and destserver or just the sourceserver?  I'm thinking read access to the directory where the file resides?

sam

 

by: dragon-itPosted on 2009-09-15 at 12:24:08ID: 25338306

Back on a proper connection now... sorry for half answers earlier, though you have plenty of others that should work!

The username and password you pass into the ftp script needs to be able to at least read the file and directory you are accessing on the unix box.  The windows side of the script will run as whatever user you either manually or scheduled the script to run as, and will have that user's rights to the destination.

Steve

 

by: netcmhPosted on 2009-09-15 at 12:33:12ID: 25338421

On the sourceserver, create the ftp user, eg. Tom

# adduser -c 'FTP USER Tom' -m tom
# passwd tom

Now tom can login using our ftp server.

If you're running redhat, make sure the following is set in vsftpd.conf

local_enable=YES

Restart the vftpd:
# service vsftpd restart

 

by: elwayisgodPosted on 2009-09-15 at 12:36:42ID: 25338463

It's AIX I believe...

 

by: elwayisgodPosted on 2009-09-15 at 13:48:15ID: 25339315

celzo76 I get this when I try that OPEN command


D:\Hyperion\CFM>OPEN my.ftp.com
'OPEN' is not recognized as an internal or external command,
operable program or batch file.

 

by: elwayisgodPosted on 2009-09-15 at 13:50:26ID: 25339332

dragon,

I get same error... Do I have to go into some ftp mode first?

D:\Hyperion\CFM>open bacpmtst1
'open' is not recognized as an internal or external command,
operable program or batch file.

 

by: elwayisgodPosted on 2009-09-15 at 13:58:34ID: 25339430

When I goto command prompt on my laptop and type c:\ftp

I get the >ftp prompt

When I do the same on the Windows box, it just sits there and doesn't give me >ftp prompt.

That seems like a issue to me.  Is ftp automatically included on Win 2003 server?

 

by: dragon-itPosted on 2009-09-15 at 14:09:26ID: 25339561

FTp should be there, though it won't be at c:\ftp, though.  Have you called a batch file ftp.cmd at all perhaps, in which case that will run before any ftp.exe from the path etc.

BTW try Qlemo's post, mine was typed while distracted and plain wrong!

Steve

 

by: netcmhPosted on 2009-09-15 at 14:13:03ID: 25339595

after you type in ftp at the prompt, adn get the >

you can type in open sourceserver

it'll ask for creds, and then you should be in

 

by: dragon-itPosted on 2009-09-15 at 14:32:17ID: 25339787

If you want to do it with the one file method you either use:

save this lot as ftpscript.txt:

open sourceserver
unixusername
unixpassword
lcd D:\cfm
cd /home/hyperion
asc
get filename.txt
quit

then in a batch file:

@echo off
ftp -i -ss:ftpscript.txt

OR use the -n option and add USER before the username, i.e.

open sourceserver
USER unixusername
unixpassword
lcd D:\cfm
cd /home/hyperion
asc
get filename.txt
quit

then in a batch file:

@echo off
ftp -n -i -ss:ftpscript.txt

or wrap all that into one batch file like Qlemo's.

 

by: QlemoPosted on 2009-09-15 at 14:51:00ID: 25339992

Steve,

Is the   -ss:    in ftp a typo, meaning   -s:, or something special?

 

by: dragon-itPosted on 2009-09-15 at 14:55:23ID: 25340021

oops, smartarse :-)  

Something special eh... I prefer gigglebiz (google it, you can see what I get to watch on the telly)

Steve

 

by: QlemoPosted on 2009-09-15 at 15:01:09ID: 25340063

I 'm just asking - I do not know nothing a lot :-D

 

by: elwayisgodPosted on 2009-09-17 at 10:12:26ID: 25358546

OK. So when I just type 'ftp' at command prompt it opens up ftp.  Then I type 'open' and it says 'To'. What is that? Do I just modify script to call ftp.exe first?  Little confused on how to get ftp to open via script.

C:\Documents and Settings\admin>ftp
ftp> open
To

 

by: dragon-itPosted on 2009-09-17 at 10:16:42ID: 25358596

The command you run is a batch / command file.  Save the following two lines as "myftp.cmd" using notepad .... don't call it ftp.cmd or it will run itself at line 2 and do nothing ...

@echo off
ftp -n -i -s:ftpscript.txt

or

@echo off
ftp -i -s:ftpscript.txt

pointing at a file ftpscript.txt (or whatever you want to call it) with the commans you want it to run in as described above.

For testing what commands you want it type:

ftp <return>
open ip of unixbox
username
password
ls
quit

will give you a directory of the default dir on the unix box.

 

by: QlemoPosted on 2009-09-17 at 10:17:08ID: 25358607

The -s:filename  in FTP uses the file as FTP commands. If you say

ftp -n -i -s:somescript.ftp

it should be executed.

 

by: dragon-itPosted on 2009-09-21 at 15:11:48ID: 25388160

elwayisgod - any luck with this, do you need any more help?

Steve

 

by: elwayisgodPosted on 2009-09-22 at 06:58:25ID: 25392859

Hi,

I'm working on it today as I didn't have time in last week or so.  I will be on it today until I get it working.  I will update later.  Not sure which solution to try :)

sam

 

by: elwayisgodPosted on 2009-09-22 at 10:48:13ID: 25395511

Hi,

Anyway to mask/hide the username and password or just the password?

Thanks,

Sam

 

by: dragon-itPosted on 2009-09-22 at 11:27:31ID: 25395922

No, sorry.

 

by: dragon-itPosted on 2009-09-22 at 11:28:08ID: 25395927

if you mean in the script.... you can run the ftp.exe line with >afile.txt or >nul on the end to mask anything it shows on the screen if you like.

Steve

 

by: dragon-itPosted on 2009-09-22 at 11:28:40ID: 25395933

i.e.

ftp -i -s:ftpscript.txt >NUL 2>&1

would run it as hidden as it can.

 

by: QlemoPosted on 2009-09-22 at 12:01:46ID: 25396251

... but in the script, credentials remain in clear text ...

 

by: QlemoPosted on 2009-09-22 at 12:02:37ID: 25396259

(and BTW, FTP itself is sending user and password unencrypted)

 

by: dragon-itPosted on 2009-09-22 at 12:39:21ID: 25396664

Hence my "no, sorry" as first answer there.  Not ideal but best you can do really with ftp.exe.  There may be other ways with gui apps etc. where you can store the password within the app "hidden" or encrypted but for this it is going to be visible -- so best to create (as would always suggest anyway for scripts) a specific account with just the necessary read or write rights only... you wouldn't run it with root or admin user of course in a script so just create a user/password which is of little user to anyone anyway if found.

 

by: elwayisgodPosted on 2009-09-23 at 08:32:07ID: 25404355

OK.  So I'm trying to run and it's not taking the username and password.  Here are the steps I'm taking:

1-At command line I type:  ftp -n -i -s:cfm_ftp_script.txt > cfm_extract_log.log
2-'cfm_ftp_script.txt' consists of:

open bbacpmtst11
e33base
Cube_Em#
lcd d:\hyperion\cfm
cd ..
cd ..
cd essbase111
ls -al
asc
get cfm_extract2.txt
bye

3-Erorr as it wont take username and pw which are correct:

ftp> Connected to bbacpmtst11

open bbacpmtst11
220 bbacpmtst11 FTP server (Version 4.2 Wed Oct 1 09:40:05 CDT 2008) ready.
ftp> Invalid command.

ftp> e33base
Invalid command.

ftp> Cube_Em#
Local directory now D:\hyperion\CFM.

ftp> lcd d:\hyperion\cfm
cd ..
530 Please login with USER and PASS.

ftp> cd ..
530 Please login with USER and PASS.

ftp> cd essbase111
530 Please login with USER and PASS.

ftp> ls -al
530 Please login with USER and PASS.

530 Please login with USER and PASS.

ftp> asc
200 Type set to A; form set to N.
ftp> get cfm_extract2.txt
530 Please login with USER and PASS.

ftp> bye
221 Goodbye.


 

by: dragon-itPosted on 2009-09-23 at 08:41:16ID: 25404496

You need to add USER before the username if you use the -n parmeter or remove the -n parameter (whether to auto prompt for logon or not).

There have been lots of posts here but details in post http:#25339787 above.

Steve

 

by: elwayisgodPosted on 2009-09-23 at 11:49:44ID: 31629050

Both of you contributed to final code which was very close to what you gave me.  Appreciate it.

 

by: elwayisgodPosted on 2009-09-25 at 07:53:04ID: 25423586

Hi,

Was wondering if there is a way to use variables in my text file?  I declare variables in my batch by calling my 'setenv.cmd' file with all the declarations.  Then in the .bat file I have a line:

ftp -i -s:cfm_ftp_script.txt

Then my cfm_ftp_script.txt file looks like below.  I want to use the variables for 'server' 'ftpuser' etc..... Can I do that?  I tried wrapping them with % and also prefix with $ but neither worked...

open server
ftpuser
ftppwd
lcd d:\hyperion\cfm
cd ..
cd ..
cd essbase111
ls -al
asc
get cfm_extract.txt
bye

 

by: dragon-itPosted on 2009-09-25 at 14:05:05ID: 25427247

Have posted in your other Q...

 

by: elwayisgodPosted on 2009-09-25 at 16:59:39ID: 25428198

OK. I figured I better post a question :)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...