Windows – Upload folder with cURL and FTP using Batch file on Windows

batch filecurlftpwindows 7

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

Best Answer

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%
)
Related Question