批量文件将.txt上传到FTP

时间:2011-10-29 09:13:51

标签: windows batch-file cmd ftp

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

以下是信息:

FTP Username: ahk@proflightsimulatoreview.com
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

请告诉我如何批量处理。我的理解是你使用FTP命令创建一个单独的txt文件,然后使用批处理文件来运行它。好吧,我必须没有插入信息,因为它不起作用。

所以我在这里给你提供信息。请告诉我如何上传文本文件。

4 个答案:

答案 0 :(得分:13)

我只是将HELLO.TXT放在你的ftp root中;

<强> 1 即可。将其保存为MYFTP.bat

@echo off
echo user ahk@proflightsimulatoreview.com> 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 即可。从命令行,与MYFTP.BAT在同一目录中,运行;

MYFTP.BAT c:\temp\hello.txt

结果

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 ahk@proflightsimulatoreview.com
331 User ahk@proflightsimulatoreview.com 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.

答案 1 :(得分:5)

我这样做了:

第一次击球:

startupload.bat
ftp -i -s:upload.bat
第二次击球: upload.bat:

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

通过打开startupload.bat来运行它(如果它不起作用,请打开cmd.exe并在其中移动startupload.bat然后按Enter键。它会显示问题所在的位置)

答案 2 :(得分:0)

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

@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: - 您可以将要上传的文件存储在批处理文件所在的同一目录中,或者使用absoulte path给出文件名。我需要上传一个名为register.exe的文件我应该使用

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

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

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

如果我的服务器名称是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

答案 3 :(得分:0)

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

(
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


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