Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FTP automation script

Posted on 2011-09-28
3
Medium Priority
?
332 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 59

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 59

Accepted Solution

by:
Bill Prew earned 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…

926 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