0

I need to upload zip files to an FTP server.

My first file looks like this:

sqlcmd -S .\SQLEXPRESS -U <user> -P <pass> -i c:\sql_script.sql
7za a -tzip %~dp0\Archive\Backup_daily_full.zip *.bak -v100m

For uploading a single file I created this:

@echo off
echo user {user}> ftpcmd.dat
echo {pass}>> ftpcmd.dat
echo put %1>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat  {server}

I don't know how many .zip files I will have after the backup and how to upload all of them on FTP (how to call that file within main .bat) OR how to simply upload them all at once.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Lexozz
  • 15
  • 1

2 Answers2

0

Add a third line to your first file:

cmd /c <your-ftp-script>.bat <zip-file-name>

As for traversing through a list of zip files, do as the manual says (cmd /?):

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

Walks the directory tree rooted at [drive:]path, executing the FOR statement in each directory of the tree. If no directory specification is specified after /R then the current directory is assumed. If set is just a single period (.) character then it will just enumerate the directory tree.

So store your zipped backup files at a clean location, then use for /r to go through the list, calling your second bat file in a loop.

Adam Adamaszek
  • 3,914
  • 1
  • 19
  • 24
0

You can loop over all the .zip files in the folder, and run the ftp script for each of them.

@echo off
for /r %~dp0\Archive %%a in (*.zip) do (
echo user {user}> ftpcmd.dat
echo {pass}>> ftpcmd.dat
echo put %%a>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat  {server}
)
Bali C
  • 30,582
  • 35
  • 123
  • 152