FTP Command Line

  • Thread starter Thread starter Evan Camilleri
  • Start date Start date
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
 
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.
 
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
 
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
 
Back
Top