Link to home
Start Free TrialLog in
Avatar of LuckyLucks
LuckyLucks

asked on

FTPing files one by one to the FTP server using batch

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
Avatar of Santosh Gupta
Santosh Gupta

how you are transferring the file.... using FTP command ?
Avatar of LuckyLucks

ASKER

yes ftp command from dos batch
Avatar of bbao
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
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.
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
)
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.
ASKER CERTIFIED SOLUTION
Avatar of ZabagaR
ZabagaR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial