Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp batch question

Status
Not open for further replies.

leahyj

MIS
May 5, 2004
107
US
Hi,

I have a batch file that ftps. Here is what it does.

1. It creates a directory listing file of all directories in the current directory.
2. It changes the current directory to each sub directory.
3. It creates a file listing file of all files in the subdirectory.
4. It ftps each file in the subdirectory using the file listing file as its file source to ftp.

It partially works, but only works for the last subdirectory.

I need someone to tell me where my logic is wrong.

Code:
SET _SourceDir=C:\red

DIR /A:D /B > filedir.txt

SET _SourceFile=filedir.txt

for /F %%B in (%_SourceFile%) do ( 

	cd /d %_SourceDir%\%%B

	dir /A:-d /B > %%Bfiles.txt

	SET _UploadFiles=%%Bfiles.txt


		for /F %%G in (%_UploadFiles%) do (
			ECHO open serverip > %_SourceDir%\%%B\script_ftp.txt
			ECHO user username password >> %_SourceDir%\%%B\script_ftp.txt
			ECHO put %%G >> %_SourceDir%\%%B\script_ftp.txt
			ECHO bye >> %_SourceDir%\%%B\script_ftp.txt

			ftp -v -i -n -s:%_SourceDir%\%%B\script_ftp.txt
		
		)


) 

cd /d %_SourceDir%

Thanks
 
I figured it out myself...
used the /R switch of the FOR command instead.


Code:
SET CURDIR=%CD%

FOR /R %CURDIR% %%G IN (*.*) DO (
    ECHO open serverip > script_ftp.txt
    ECHO user username password >> script_ftp.txt
    ECHO put %%G >> script_ftp.txt
    ECHO bye >> script_ftp.txt
    ftp -v -i -n -s:script_ftp.txt
        
)

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top