Link to home
Start Free TrialLog in
Avatar of oconnork00
oconnork00Flag for United States of America

asked on

Upload entire folder contents via FTP

Hi all,

I'd like to upload the entire contents of a temp folder using a batch file

Here's the code I'm using:
@echo off
echo user kevin@mydomain.com> ftpcmd.dat
echo mypassword>> ftpcmd.dat
echo mkdir "NewDirectoryName">> ftpcmd.dat
echo ascii>> ftpcmd.dat
echo cd /public_html/>>ftpcmd.dat
echo cd NewDirectoryName>>ftpcmd.dat
echo put *.* "C:\Users\Kevin\Desktop\temp">> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat mydomain.com
del ftpcmd.dat

Open in new window


I can create the directory fine, I just want to then be able to upload the entire contents of the temp directory C:\Users\Kevin\Desktop\temp" and I thought he echo put *.* would have done it for me but no luck.

Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

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
Avatar of skullnobrains
skullnobrains

i highly recommend you do not try to do this using a windows batch file
it will be long, complicated, inefficient, and probably likely to break on weird file names

there are plenty of tools around that can do what you want such as this one
http://curl.haxx.se/download.html
pick the windows 2000/xp binaries, they will work on vista and seven
this tools will also work with various other protocols such as http, sftp, ... and will work through authenticating proxies and any setup you can come up with

alternatively, you can also mount a remote ftp directory in windows and use a regular recursive copy
You can send multiple files at once using MPUT rather than PUT.   In addition it looks like there are some other issues with your file.  You seem to create the new directory in one place, and then try to CD to it someplace else?  I think this might be closer to what you want, but not sure if I completely understand the folders involved.

@echo off
echo user kevin@mydomain.com> ftpcmd.dat
echo mypassword>> ftpcmd.dat
echo ascii>> ftpcmd.dat
echo cd /public_html/>>ftpcmd.dat
echo mkdir "NewDirectoryName">> ftpcmd.dat
echo cd NewDirectoryName>>ftpcmd.dat
echo lcd "C:\Users\Kevin\Desktop\temp">> ftpcmd.dat
echo put *.*>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat mydomain.com
del ftpcmd.dat

Open in new window

For what it's worth, I really like NCPFTP Client for this type of thing, you can do everything with a single command line.  Take a look at:

http://www.ncftp.com/ncftp/

~bp
billprew,
you're still using "put" in your script.
"mput" will (according to the information at hand, can't verify it) ask for confirmation for each file, though, so this is not the best solution for an unattended ftp file.
My guess about the folder names is that that the "cd /public_html/" is an accidental leftover from generalizing the file/folder names involved.
Avatar of oconnork00

ASKER

oBdA
Your solution is great. Can you see, though, why I'm unable to create a new folder inside one of the folders I created?
set SourceFolder=C:\Users\Kevin\Desktop\temp\Garage\2
set SourceMask=*.*
echo user MYLOINNAME> ftpcmd.dat
echo PASSWORD>> ftpcmd.dat
echo ascii>> ftpcmd.dat
echo cd /public_html>>ftpcmd.dat
echo mkdir "Garage">> ftpcmd.dat
echo cd Garage>>ftpcmd.dat
echo mkdir "2">> ftpcmd.dat
for %%a in ("%SourceFolder%\%SourceMask%") do (
>>ftpcmd.dat echo put "%%~a"
)

Open in new window


What I want to do is create that folder called "2" inside the folder called "Garage" but it doesnt. However it does upload the files fine, but it puts them in the "Garage" folder instead of "Garage>2" folder
Ah yes, cut and paste with no change to the PUT, doh.

I'm pretty sure there is an option in FTP to disable to prompting on each file, which is -i.

So, add that to the command line as follows:

ECHO ftp -i -n -s:ftpcmd.dat mydomain.com

~bp
You're missing the cd "2" command after the mkdir.
Excellent solution, thank you.