命令行上传ftp_如何从Windows命令行自动执行FTP上传
命令行上传ftp
Windows has included batch files since before it existed… batch files are really old! Old or not, I still find myself frequently creating batch files to help me automate common tasks. One common task is uploading files to a remote FTP server. Here’s the way that I got around it.
Windows自存在以来就包含批处理文件…批处理文件确实很旧! 不论年龄长与短,我仍然发现自己经常创建批处理文件来帮助我自动执行常见任务。 一项常见任务是将文件上传到远程FTP服务器。 这是我解决问题的方法。
First, you will have to create a file called fileup.bat in your windows directory, or at least inside some directory included in your path. You can use the “path” command to see what the current path is.
首先,您将必须在Windows目录中或至少在路径中包含的某个目录中创建一个名为fileup.bat的文件。 您可以使用“ path”命令查看当前路径。
Inside the batch file, you will want to paste the following:
在批处理文件中,您将要粘贴以下内容:
@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 SERVERNAME.COM del ftpcmd.dat
@echo关闭回显用户MyUserName> ftpcmd.dat回显MyPassword >> ftpcmd.dat回显bin >> ftpcmd.dat回显%1 >> ftpcmd.dat回显退出>> ftpcmd.dat ftp -n -s:ftpcmd.dat服务器名.COM del ftpcmd.dat
You will want to replace the MyUserName, MyPassword and SERVERNAME.COM with the correct values for your ftp server. What this batch file is doing is scripting the ftp utility using the -s option for the command line utility.
您将要用正确的ftp服务器值替换MyUserName,MyPassword和SERVERNAME.COM。 该批处理文件正在使用命令行实用程序的-s选项编写ftp实用程序脚本。
The batch file uses the “echo” command to send text to the ftp server as if you had typed it. In the middle of the file you can add extra commands, potentionally a change directory command:
批处理文件使用“ echo”命令将文本发送到ftp服务器,就像您键入它一样。 在文件的中间,您可以添加其他命令,有可能是更改目录命令:
echo cd /pathname/>>ftpcmd.dat
回声cd /pathname/>>ftpcmd.dat
In order to call this batch file, you will call the batchfile using the fileup.bat name that we gave it, and pass in the name of a file as the parameter. You don’t have to type the .bat part of the filename to make it work, either.
为了调用该批处理文件,您将使用我们为其指定的fileup.bat名称来调用该批处理文件,并传入文件名作为参数。 您也不必键入文件名的.bat部分即可使其工作。
Example:
例:
> fileup FileToUpload.zip
> fileup FileToUpload.zip
Connected to ftp.myserver.com. 220 Microsoft FTP Service ftp> user myusername 331 Password required for myusername.
连接到ftp.myserver.com 。 220 Microsoft FTP服务ftp>用户myusername 331 myusername所需的密码。
230 User myusername logged in. ftp> bin 200 Type set to I. ftp> put FileToUpload.zip 200 PORT command successful. 150 Opening BINARY mode data connection for FileToUpload.zip 226 Transfer complete. ftp: 106 bytes sent in 0.01Seconds 7.07Kbytes/sec. ftp> quit
230用户myusername登录。ftp> bin 200类型设置为I。ftp> put FileToUpload.zip 200 PORT命令成功。 150打开FileToUpload.zip的BINARY模式数据连接226传输完成。 ftp:106个字节,以0.01秒为单位发送7.07 KB /秒。 ftp>退出
And that’s all there is to it. Now your file should be sitting on the remote server.
这就是全部。 现在,您的文件应该位于远程服务器上。
-
› How to Quickly Scroll Through Home Screen Pages on iPhone and iPad
-
› How to Move a Window to Another Virtual Desktop on Windows 10
-
› What’s the Deal with Google Home and Nest? Is There a Difference?
翻译自: https://www.howtogeek.com/howto/windows/how-to-automate-ftp-uploads-from-the-windows-command-line/
命令行上传ftp