Solved

FTP automation script

Posted on 2011-09-28
3
322 Views
Last Modified: 2012-05-12
Need script in  windows batch or WSH.

FTP all files in predefined local directory,
to corresponding directory on remote server.

Directory on remote server  needs to be created if it does not exists, or copy to existing one if directory exists on remote server.
After transfer need to log summary - files in local directory, files in remote directory,
Can not install any 3-d party ftp programs on the server.

0
Comment
Question by:Larissa T
[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
  • 2
3 Comments
 
LVL 56

Expert Comment

by:Bill Prew
ID: 36719778
Some good discussion on FTP automation here:

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_27272929.html

That being said, I think a BAT script something like this should do the job.  The log file will show all files that were transferred.  If you want another full listing of the files you can use the LS and DIR subcommands at the end of the ftp commands.

@echo off
(echo open 10.x.x.x
echo user username 
echo password
echo lcd c:\temp
echo mkdir /destination/path
echo cd /destination/path
echo bin
echo mput *.*
echo quit
) | ftp -n -i > log.txt

Open in new window

~bp
0
 
LVL 11

Author Comment

by:Larissa T
ID: 36807649
Directory name is different - can it be parameter.
How I validate if directory exists on remote server
0
 
LVL 56

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 36814196
Here's how to pass the remote folder name in as a command line parm to the script.

There's no easy way to check the existence of a remote folder in FTP, so I just added a line to always try to create it.  If it already exists it will display a warning and then do the rest of the transfer. If it doesn't exist it will create it.

@echo off
setlocal

REM Get destination folder path from command line
if "%~1" NEQ "" (
  set DestPath=%~1
) else (
  echo ERROR - Missing remote folder path.
  goto :EOF
)

REM FTP files to remote server
(echo open 10.x.x.x
echo user username 
echo password
echo lcd c:\temp
echo mkdir %DestPath%
echo cd %DestPath%
echo bin
echo mput *.*
echo quit
) | ftp -n -i > log.txt

Open in new window

~bp
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

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.

Join & Ask a Question