Solved

FTP automation script

Posted on 2011-09-28
3
290 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 52

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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
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…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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…

861 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

25 Experts available now in Live!

Get 1:1 Help Now