簡體   English   中英

無法通過批處理腳本中的 FTP 上傳目錄中的文件和文件夾

[英]Cannot upload files and folders in directory via FTP in batch script

我有幾個文件夾希望通過 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 中,我可以在 ZDFFF0A7FA1A55C8C1452ZZFDA6 中運行 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但它什么也沒做。

Windows 命令行ftp.exe客戶端不支持遞歸操作。

您必須使用第 3 方 FTP 客戶端。


例如,您可以使用WinSCP

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

將 Windows ftp.exe腳本轉換為 WinSCP 腳本的指南。 雖然更簡單的是讓WinSCP GUI 為您生成腳本或批處理文件

(我是WinSCP的作者)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM