[英]Batch file to upload .txt to FTP
我为此设置了一个单独的 FTP 帐户。
这是信息:
FTP Username: ahk@proflightsimulatoreview.com
FTP Server: ftp.proflightsimulatoreview.com
FTP Server Port: 21
FTP Password: ahktest
我要上传的文本文件: C:\\Users\\Kyle\\Desktop\\ftptest\\thetest.txt
请告诉我如何用批处理来做到这一点。 我的理解是,您使用 FTP 命令创建一个单独的 txt 文件,然后使用批处理文件来运行它。 好吧,我一定没有正确插入信息,因为它不起作用。
所以我在这里给你信息。 请教我如何上传文本文件。
我只是把 HELLO.TXT 放在你的 ftp 根目录下;
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.
我是这样做的:
第一棒:
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。它会告诉您问题出在哪里)
像这样创建一个批处理文件:
@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
: - 您可以将要上传的文件存储在批处理文件所在的同一目录中,或者使用绝对路径指定文件名。即我需要上传一个名为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
上传到服务器的简单方法是制作一个脚本文件:
代码 :
(
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://)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.