FTP Command Line

E

Evan Camilleri

I did the following FTP script:

open myhost
user
password
binary
hash
lcd c:\mypath\backups
mput *.*
bye

This uploads all files BUT not subdirectories. Is there a way to do it by
command prompt?

Evan
 
P

Phil Robyn

Evan said:
I did the following FTP script:

open myhost
user
password
binary
hash
lcd c:\mypath\backups
mput *.*
bye

This uploads all files BUT not subdirectories. Is there a way to do it by
command prompt?

Evan

Yes, but what you need is a batch file that generates your script,
adding in the appropriate 'cd', 'lcd' and 'mput' commands for each
subdirectory, and then invokes the generated script.
 
W

Willem Kossen

Phil Robyn said:
Yes, but what you need is a batch file that generates your script,
adding in the appropriate 'cd', 'lcd' and 'mput' commands for each
subdirectory, and then invokes the generated script.

That would be something along the lines of:

@echo off

set basepath=c:\mypath\backups

echo open myhost >commands.txt
echo user>>commands.txt
echo password>>commands.txt
echo binary>>commands.txt
echo hash>>commands.txt
echo lcd %basepath%>>commands.txt
echo mput *.*>>commands.txt
for /f "delims=|" %%q in ('dir /b/ad %basepath%\* ') do(
::note, you may need to remotely create directories first....i presume
they exist...
echo cd %%q>>commands.txt
echo lcd %basepath%\%%q>>commands.txt
echo mput *.*>>commands.txt
)
echo bye>>commands.txt

ftp<commands.txt

test before using this in production environments.... i haven't tested this,
just showed the concept...

Willem
 
E

Evan Camilleri

Great!
Thanks. Will test and get back!

Evan

Willem Kossen said:
Phil Robyn said:
Yes, but what you need is a batch file that generates your script,
adding in the appropriate 'cd', 'lcd' and 'mput' commands for each
subdirectory, and then invokes the generated script.

That would be something along the lines of:

@echo off

set basepath=c:\mypath\backups

echo open myhost >commands.txt
echo user>>commands.txt
echo password>>commands.txt
echo binary>>commands.txt
echo hash>>commands.txt
echo lcd %basepath%>>commands.txt
echo mput *.*>>commands.txt
for /f "delims=|" %%q in ('dir /b/ad %basepath%\* ') do(
::note, you may need to remotely create directories first....i presume
they exist...
echo cd %%q>>commands.txt
echo lcd %basepath%\%%q>>commands.txt
echo mput *.*>>commands.txt
)
echo bye>>commands.txt

ftp<commands.txt

test before using this in production environments.... i haven't tested
this,
just showed the concept...

Willem
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top