?
Solved

FTPing files one by one to the FTP server using batch

Posted on 2014-03-15
8
Medium Priority
?
335 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
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.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

764 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