windows 将 .txt 上传到 FTP 的批处理文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7937963/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:52:37  来源:igfitidea点击:

Batch file to upload .txt to FTP

windowsbatch-filecmdftp

提问by kmoney12

I have setup a separate FTP account for this.

我为此设置了一个单独的 FTP 帐户。

Here is the info:

这是信息:

FTP Username: [email protected]
FTP Server: ftp.proflightsimulatoreview.com
FTP Server Port: 21
FTP Password: ahktest

Text file I want to upload: C:\Users\Kyle\Desktop\ftptest\thetest.txt

我要上传的文本文件: C:\Users\Kyle\Desktop\ftptest\thetest.txt

Please show me how to do this with batch. My understanding is that you make a separate txt file with the FTP commands and then you use a batch file to run it. Well I must have not plugged in the info right because it didn't work.

请告诉我如何用批处理来做到这一点。我的理解是,您使用 FTP 命令创建一个单独的 txt 文件,然后使用批处理文件来运行它。好吧,我一定没有正确插入信息,因为它不起作用。

So here I am giving you the information. Please show me how to upload a text file.

所以我在这里给你信息。请教我如何上传文本文件。

回答by Alex K.

I just put HELLO.TXT in your ftp root by;

我只是把 HELLO.TXT 放在你的 ftp 根目录下;

1. Saving this as MYFTP.bat:

1. 将其保存为MYFTP.bat

@echo off
echo user [email protected]> ftpcmd.dat
echo ahktest>> ftpcmd.dat
echo put %1>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat ftp.proflightsimulatoreview.com
del ftpcmd.dat

2. From the command line, in the same directory as MYFTP.BAT, running;

2. 从命令行,在与 相同的目录中MYFTP.BAT,运行;

MYFTP.BAT c:\temp\hello.txt

result

结果

220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
220-You are user number 2 of 50 allowed.
220-Local time is now 05:17. Server port: 21.
220 You will be disconnected after 15 minutes of inactivity.
ftp> user [email protected]
331 User [email protected] OK. Password required

230-OK. Current restricted directory is /
230 0 Kbytes used (0%) - authorized: 51200 Kb
ftp> put hello.txt
200 PORT command successful
150 Connecting to port 59363
226-0 Kbytes used (0%) - authorized: 51200 Kb
226-File successfully transferred
226 0.563 seconds (measured here), 14.20 bytes per second
ftp: 8 bytes sent in 0.34Seconds 0.02Kbytes/sec.
ftp> quit
221-Goodbye. You uploaded 1 and downloaded 0 kbytes.
221 Logout.

回答by non-english guest

I did it like that:

我是这样做的:

1st bat:

第一棒:

startupload.bat
ftp -i -s:upload.bat

2nd bat: upload.bat :

第二个蝙蝠:upload.bat:

open ftp.yourserver.com
username 
password 
cd public_html 
cd Ftp 
binary
put C:\Users\Desktop\something.txt
bye

you run it by opening startupload.bat(if that doesn't work, open cmd.exeand move startupload.batin it and hit Enter. It will show you where is problem)

你通过打开来运行它startupload.bat(如果这不起作用,打开cmd.exe并移动startupload.bat它并按 Enter。它会告诉你哪里有问题)

回答by Vivek S.

Create a batch file like this:

像这样创建一个批处理文件:

@echo off

echo USERNAME> upload.txt
echo PASSWORD>> upload.txt
echo asc>>upload.txt
echo put UPLOAD_FILE_NAME FTP_PATH_TO_STORE_FILE>> upload.txt
echo quit >> upload.txt


ftp -s:upload.txt SERVER_NAME.COM

del upload.txt

UPLOAD_FILE_NAME: - you can store file to be uploaded in the same directory where the batch file exists or give file name with absoulte path.I.e I need to upload a file called register.exeI should use

UPLOAD_FILE_NAME: - 您可以将要上传的文件存储在批处理文件所在的同一目录中,或者使用绝对路径给出文件名。即我需要上传一个名为register.exe我应该使用的文件

echo put register.exe, If register.exeis exists in the batch directory or echo put d:\myfiles\register.exe, If register.exeis exists in another folder(myfiles folder in d drive)

echo put register.exe, 如果register.exe存在于批处理目录或 echo put d:\myfiles\register.exe, 如果register.exe存在于另一个文件夹中(d 盘中的 myfiles 文件夹)

FTP_PATH_TO_STORE_FILE:- This is the FTP path where I need to put my file.For example /home/myftpfolder/register.exe

FTP_PATH_TO_STORE_FILE:- 这是我需要放置文件的 FTP 路径。例如 /home/myftpfolder/register.exe

del upload.txt:- its optional because when executes batch file this upload.txtwill stores in the directory with FTP username and password

del upload.txt:- 它是可选的,因为当执行批处理文件时,这upload.txt将存储在具有 FTP 用户名和密码的目录中

If I've my server name is theserver.comthen the batch file should be write like

如果我的服务器名称是,theserver.com那么批处理文件应该写成

@echo off
echo user123> upload.txt
echo 123TTyyy#>> upload.txt
echo asc>>upload.txt
echo put register.exe /home/myfiles/register.exe>> upload.txt
echo quit >> upload.txt
 ftp -s:upload.txt theserver.com
del upload.txt

回答by user6459055

The easy way to upload to server is make a script file :
Code :

上传到服务器的简单方法是制作一个脚本文件:
代码:

(
echo USERNAME
echo PASSWORD
echo asc
echo put C:\Users\Kyle\Desktop\ftptest\thetest.txt
echo quit
)>temp.txt
ftp SERVER_DOAMIN -s:temp.txt
del temp.txt /q >nul


So, the USERNAME is a username, and PASSWORD is a password, SERVER_DOMAIN is a server domain (not ftp:// at the top)


因此,USERNAME 是用户名,PASSWORD 是密码,SERVER_DOMAIN 是服务器域(不是顶部的 ftp://)