Solved

FTPing files one by one to the FTP server using batch

Posted on 2014-03-15
8
311 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:Bing CISM / CISSP
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now