Solved

FTP automation script

Posted on 2011-09-28
3
277 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
  • 2
3 Comments
 
LVL 51

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 51

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
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). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now