1

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

4 Answers 4

6

The problem is that curl doesn't cycle through the directory, there is no option for uploading the 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 https://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%
)
3

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 \;
1

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.

1
  • Am just curious, any particular reason why you didn't undelete your original answer, and edit it if required?
    – Karan
    May 3, 2013 at 17:19
1

Like the Linux solution posted earlier, in Windows you would do:

forfiles /p C:\uploads /c "curl.exe -C -# -T @path ftp://some-ftp-site/folder/@file --user user:pass"

You must log in to answer this question.

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