command-line - 需要从批处理脚本执行FTP命令

标签 command-line command batch-file

Need to write batch script which copies file from FTP to local drive

我正在尝试使用 cmd 命令提示符来实现此目的

批处理文件内

请帮助我或粘贴任何线索。

我找到了答案,非常感谢,但是,

我需要使用 2 个文件 script.txtbatch.bat

其中包含 script.txt 代码:

open ftp.server.com
username
password
cd folderpath/newfolder
get file1.xml
close
bye

和batch.bat代码

ftp -v -i -s:script.txt
echo done!

But How can i do it using only .bat file so that I need only 1 file not 2 files

最佳答案

作为起点:

  1. Perform a NSLOOKUP for the FTP site, e.g. nslookup ftp.microsoft.com make a note of the IP address
  2. Edit the LMHOSTS file (in %systemroot%\system32\drivers\etc)
  3. Add line MicrosoftFTP #PRE e.g. 207.46.133.140 MicrosoftFTP #PRE
  4. Save the file
  5. Open a CMD.EXE session. Enter command: nbtstat -R This purges and reloads the name table cache
  6. Type command: net view \MicrosoftFTP You should see information on the site
  7. Now map a drive (to share data) net use * \MicrosoftFTP\data /user:anonymous
  8. All done. It will pass a drive letter for the connection

下一步是通过编写命令脚本并使用 file/string manipulation 使步骤 1-4 自动化。如有必要,更新主机文件。

有了映射的驱动器,您就可以从一个驱动器到另一个驱动器进行正常的 Xcopy。

引用: http://answers.yahoo.com/question/index?qid=20080612073002AAruBR0

更新响应您的编辑:

在主batch.bat文件中,动态创建script.txt,如下所示:

@echo off 
@echo open ftp.server.com > script.txt
@echo username >> script.txt
@echo password >> script.txt
@echo cd folderpath/newfolder >> script.txt
@echo get file1.xml >> script.txt
@echo close >> script.txt
@echo bye >> script.txt

然后做

ftp -v -i -s:script.txt

最后 - 进行整理,删除临时 script.txt:

del script.txt

关于command-line - 需要从批处理脚本执行FTP命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12620557/

相关文章:

powershell - 如何运行带有BAT文件中极长参数的程序?

java - 在命令行上编译 netbeans 程序

node.js - 我可以在后台运行 Node.js 命令行应用程序并通过按键调用它吗?

javascript - 使用命令清除控制台

shell - 在每个文本文件的顶部和底部添加新行

node.js - 列出git中master和当前分支之间的所有文件?如果有任何 Node 包可以将结果推送到数组 :) 中,那就太好了

用于将文件复制到文件夹的 Windows 批处理脚本

java - 调用 Java Web Service 时包含 .bat 扩展名

postgresql - 在 PSQL 上进行基本查询不显示任何内容

c - 将多个数据加载到命令行 c