Solved

FTPing files one by one to the FTP server using batch

Posted on 2014-03-15
8
323 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
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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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 500 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
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…

762 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