?
Solved

FTPing files one by one to the FTP server using batch

Posted on 2014-03-15
8
Medium Priority
?
336 Views
Last Modified: 2014-03-27
Hi

I have a txt file containing full path of the files I need to transfer to the FTP site.

For example my txt file - txt1.txt contains the following contents:

\\myserver1\file1
\\myserver2\file2
etc

I need to FTP each file to the ftp server sat myftp.xyz.com and write out to a log of any failed transfers. We can call the log file log_txt1.txt.


Can you help me with the batch code? Thanks
0
Comment
Question by:LuckyLucks
[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
8 Comments
 
LVL 13

Expert Comment

by:Santosh Gupta
ID: 39931671
how you are transferring the file.... using FTP command ?
0
 

Author Comment

by:LuckyLucks
ID: 39932035
yes ftp command from dos batch
0
 
LVL 37

Expert Comment

by:bbao
ID: 39932122
why my first comment was gone?

just follow below instructions to upload files with the local files part replaced with your file names in UNC format.

FYI
superuser.com/questions/323214/how-to-upload-one-file-by-ftp-from-command-line
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:LuckyLucks
ID: 39932202
The O/S is windows 2003 server.

Also, i need to iterate thru each file and pass it to the FTP block.


The link doesnt help with either.
0
 
LVL 15

Expert Comment

by:ZabagaR
ID: 39933108
I just tested this code myself and it does just what you want:

Here is the explanation:

 - c:\temp\files.txt contains a LIST of files I want to FTP in UNC format as you required
 - edit my script and use your FTP site, username and password & destination folder.
 - my script is putting each file on my FTP server in a folder called \myfolder\
 - the file c:\ftpout.txt is the log file you can review when done
 - don't change the spacing between the ftp code and the >> characters

mytestscript.bat:

setlocal EnableDelayedExpansion
FOR /F %%i in (c:\temp\files.txt) do (
echo open myftpsite.com > c:\mycommands.txt
echo username>> c:\mycommands.txt
echo password>> c:\mycommands.txt
echo bin>> c:\mycommands.txt
echo prompt n>> c:\mycommands.txt
echo cd myfolder>> c:\mycommands.txt
echo put %%i>> c:\mycommands.txt
echo bye>> c:\mycommands.txt
if !errorlevel! == 0 ftp -s:c:\mycommands.txt >> c:\ftpout.txt
)
0
 

Author Comment

by:LuckyLucks
ID: 39933179
Can you get the c:\mycommands.txt as a variable so I have to change that once only? The same thing for c:ftpout.txt, c:\temp\files.txt.
0
 
LVL 15

Accepted Solution

by:
ZabagaR earned 2000 total points
ID: 39933254
Is this what you mean?

rem
set mycommands=c:\commands.txt
set myinput=c:\temp\files.txt
set logfile=c:\ftpout.txt
rem
setlocal EnableDelayedExpansion
FOR /F %%i in (%myinput%) do (
echo open myftpsite.com > %mycommands%
echo username>> %mycommands%
echo password>> %mycommands%
echo bin>> %mycommands%
echo prompt n>> %mycommands%
echo cd myfolder>> %mycommands%
echo put %%i>> %mycommands%
echo bye>> %mycommands%
if !errorlevel! == 0 ftp -s:%mycommands% >> %logfile%
)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 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