Need to write batch script which copies file from FTP to local drive
我正在尝试使用 cmd
命令提示符来实现此目的
批处理文件内
请帮助我或粘贴任何线索。
我找到了答案,非常感谢,但是,
我需要使用 2 个文件 script.txt
和 batch.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
最佳答案
作为起点:
- Perform a NSLOOKUP for the FTP site, e.g. nslookup ftp.microsoft.com make a note of the IP address
- Edit the LMHOSTS file (in %systemroot%\system32\drivers\etc)
- Add line MicrosoftFTP #PRE e.g. 207.46.133.140 MicrosoftFTP #PRE
- Save the file
- Open a CMD.EXE session. Enter command: nbtstat -R This purges and reloads the name table cache
- Type command: net view \MicrosoftFTP You should see information on the site
- Now map a drive (to share data) net use * \MicrosoftFTP\data /user:anonymous
- 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/