Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to upload a whole folder, including it's sub-folders and files to a folder on my server from a Windows batch (.bat) file.

Below is the command I have for the Upload part...

curl -T E:\Server\bootstrap3\_gh_pages\ -u USER:PASSWORD ftp://domain.com/bootstrap/

This is the error I get

curl: Can't open 'E:\Server\bootstrap3\_gh_pages\'!
curl: try 'curl --help' for more information

If I try to do just 1 file, it works fine, I need to somehow loop through and do all folders and files, any help please?

I have Googled and tried a couple not very good examples with no luck on this exact question yet

share|improve this question

You probably already figured it out, but at least for the other googlers like me:

the problem is that curl doesn't cycle through the directory, there is no option for uploading whole directory and it doesn't support *-expansion. So the solution I ended up with is to write a .bat script. With the help of this answer http://stackoverflow.com/a/9429985

@echo off 
set localdir=C:\something
set ftphost=your.ftp.host.com
set ftpuser=yourftpuser
set ftppass=yourftppassword
set ftpdir=target/directory/on/server

setlocal enableDelayedExpansion

for /F %%x in ('dir /B/D %localdir%') do (
  set FILENAME=%localdir%\%%x
  curl -T !FILENAME! ftp://%ftphost%/%ftpdir%/ --user %ftpuser%:%ftppass%
)
share|improve this answer

Since curl was written for *nix (unix), there can be problems specifying working commands from the Windows Command Prompt. This is mostly related to the processing of " (double-quote) marks, and \ (backslashes).

A simple thing you can try is:

  1. Enclose filenames in double-quotes.
  2. Escape the backslashes by adding another backslash before each desired backslash.

So, like this:

curl -T "E:\\Server\\bootstrap3\\_gh_pages\\" -u USER:PASSWORD ftp://domain.com/bootstrap/

You could also try using forward-slashes like this, which might work:

curl -T "E:/Server/bootstrap3/_gh_pages/" -u USER:PASSWORD ftp://domain.com/bootstrap/


Another thing you could try is to use the -K (or --config=) command line option switch for curl (some helpful information can be found here).

Basically, you place all the command line arguments in a file and use -K file (or --config=file) to tell curl where to find the arguments.

So, you create a file (example: test.txt) that has each command line option on a separate line like this:

-T "E:\\Server\\bootstrap3\\_gh_pages\\"
-u USER:PASSWORD
--url=ftp://domain.com/bootstrap/

Then run curl like this:

curl -K test.txt
  or
curl --config=test.txt



If none of this works, you may need to run the curl command from a Cygwin terminal window on Windows. See this webpage for info on using curl with Cygwin on Windows.

share|improve this answer
    
Am just curious, any particular reason why you didn't undelete your original answer, and edit it if required? – Karan May 3 '13 at 17:19

Not useful for Windows, but on Linux you can combine curl and find:

find /server/ -exec curl -T {} ftp://some-ftp-site/folder/ --user user:pass \;
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .