Batch file to upload all files in directory to FTP

2020-02-01 05:06发布

I'm trying to make a bat script to upload all files from a folder to an FTP server.

I followed the below guide and manage to get a single file uploaded but can't figure out how to upload everything in the folder.

How to Automate FTP Uploads from the Windows Command Line

From what I've read I think i need to somehow use the mput command?

At the moment my upload.bat file looks like this:

myftp.bat .\logs\test.txt

inside myftp.bat is:

@echo off
echo user MyUserName> ftpcmd.dat
echo MyPassword>> ftpcmd.dat
echo bin>> ftpcmd.dat
echo put %1>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat MyFTPServer
del ftpcmd.dat
pause

2条回答
等我变得足够好
2楼-- · 2020-02-01 05:19

You need to use mput command like:

cd logs
prompt
mput *

Without prompt command, you would get asked to confirm each transfer.


Instead of the prompt command, you can also use the -i switch:

ftp -i -n -s:ftpcmd.dat MyFTPServer
查看更多
地球回转人心会变
3楼-- · 2020-02-01 05:36

You could also make a batch file that runs multiple other hidden batch files so that you can transfer each file with an individual batch file. If you want the code for this, just ask but it looks like the best solution has already been said ^^.

查看更多
登录 后发表回答