【问题标题】:Cannot upload files and folders in directory via FTP in batch script无法在批处理脚本中通过 FTP 上传目录中的文件和文件夹
【发布时间】:2017-12-20 11:46:00
【问题描述】:

我有几个文件夹希望通过 FTP 上传到服务器。

这是文件夹结构:

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

我有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

run_ftp.bat 是一行,public_html/ 是服务器上文件的目的地,C:\Web\build 是文件在我的电脑上的位置:

fileup public_html/ C:\Web\build

run_ftp.bat 位于 C:\Web 中,fileup.bat 位于 C:\Windows 中,因此它出现在 PATH 中,我可以在 cmd 中运行 fileup。

当我运行run_ftp.bat 时,唯一上传到服务器的文件位于 /build 的根目录中,因此只上传了 index.html。控制台日志:Error opening local file fonts. 用于 /build 中的每个文件夹。

这是日志:

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 . . .

当我运行 .bat 文件时,构建文件夹中的所有文件都不是正在使用的文件夹,我有点难过为什么没有上传任何文件夹。我试过用ascii 替换bin,但它什么也没做。

【问题讨论】:

  • 您只有几个目录。只需执行几个更改目录命令,然后使用 mput 命令上传文件。

标签: windows batch-file cmd ftp


【解决方案1】:

Windows 命令行ftp.exe 客户端不支持递归操作。

您必须使用第 3 方 FTP 客户端。


例如 WinSCP 你可以使用:

winscp.com /log=ftp.log /command ^
    "open ftp://USERNAME:PASSWORD@ftp.example.com/" ^
    "mput ""%2\*"" ""%1""" ^
    "exit"

converting Windows ftp.exe script to WinSCP script 有一个指南。虽然更容易的是拥有WinSCP GUI generate the script or batch file for you

(我是 WinSCP 的作者)

【讨论】:

    猜你喜欢
    • 2015-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-13
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多