Solved

FTP automation script

Posted on 2011-09-28
3
305 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 53

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 53

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This is a fairly complicated script that will install the required prerequisites to install SCCM 2012 R2 on a server.  It was designed under the functional model in order to compartmentalize each step required, reducing the overall complexity.  The …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

840 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