Cannot upload files and folders in directory via FTP in batch script

Issue

I have a few folders I wish to upload to a server via FTP.

This is the folder structure:

build >
    fonts >
        - font1.ttf
        - font2.ttf
    images >
        - img1.png
        - img2.png
    javascripts >
        - script.js
    stylesheets >
        - style.css
    index.html

I have fileup.bat:

@echo off
echo user USERNAME> ftpcmd.dat
echo PASSWORD>> ftpcmd.dat
echo prompt>> ftpcmd.dat

echo cd %1>> ftpcmd.dat
echo lcd %2>>ftpcmd.dat
echo mput *.*>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat 123.456.78.9
del ftpcmd.dat
pause

And run_ftp.bat which is a single line, public_html/ is the destination of the files on the server and C:\Web\build is where the files are located on my PC:

fileup public_html/ C:\Web\build

The run_ftp.bat is located in C:\Web and fileup.bat is in C:\Windows so it appears in the PATH and I can run fileup in cmd.

When I run run_ftp.bat the only files that get uploaded to the server are in the root of /build, so only index.html is uploaded. The console logs: Error opening local file fonts. for each of the folders inside /build.

Here’s the log:

230 OK. Current restricted directory is /
ftp> prompt
Interactive mode Off .
ftp> cd public_html/
250 OK. Current directory is /public_html
ftp> lcd C:\Web\build
Local directory now C:\Web\build.
ftp> mput *.*
Error opening local file fonts.
Error opening local file images.
200 PORT command successful
150 Connecting to port 57128
226-File successfully transferred
226 0.142 seconds (measured here), 1.78 Mbytes per second
ftp: 265174 bytes sent in 0.07Seconds 3682.97Kbytes/sec.
Error opening local file javascripts.
Error opening local file stylesheets.
200 PORT command successful
150 Connecting to port 57129
226-File successfully transferred
226 0.033 seconds (measured here), 36.90 Kbytes per second
ftp: 1229 bytes sent in 0.01Seconds 102.42Kbytes/sec.
ftp> quit
221-Goodbye. You uploaded 261 and downloaded 0 kbytes.
221 Logout.
Press any key to continue . . .

None of the files are folders inside the build folder are in use when I run the .bat file, I’m a bit stumped why none of the folders are being uploaded. I’ve tried replacing bin with ascii but it does nothing.

Solution

Windows command-line ftp.exe client does not support recursive operations.

You have to use a 3rd-party FTP client.


For example with WinSCP you can use:

winscp.com /log=ftp.log /command ^
    "open ftp://USERNAME:[email protected]/" ^
    "mput ""%2\*"" ""%1""" ^
    "exit"

There’s a guide for converting Windows ftp.exe script to WinSCP script. Though easier is to have WinSCP GUI generate the script or batch file for you.

(I’m the author of WinSCP)

Answered By – Martin Prikryl

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published