How to make a batch-script that adds a line of code to a document on FTP-server?
I'm currently designing a site for a not so computer-savvy guy who wants to edit the site himself using One.com's dreadful WebCreator.
Fine by me, however WebCreator has many flaws, the most annoying being that it removes the DOCTYPE when the page is sa开发者_JAVA百科ved. WebCreator doesn't allow you to edit .php- or .shtml-files, so I have to add the DOCTYPEs after my friend has saved the page.
So what I basically want to do is to write a batch-script that the user can double-click on his Windows machine. This script-of-my-dreams would add the DOCTYPE to the top of the document and save it.
Is this possible?
I don't think so, not solely with a batch script.
One thing you could do is:
- download the file
- edit it in automated fashion to add the desired line
- upload the file.
Batch doesn't include FTP capabilities, so... batch alone wouldn't be sufficient. Supposing that you had an Ftpdriver program, something that you could script, then it wouldn't be difficult.
Something like this:
FtpDriver -download ftp://woo/hoo.htm -password xxxxx -local c:\temp\hoo.htm
echo DOCTYPE > c:\temp\extra.line.htm
copy c:\temp\extra.line.htm + c:\temp\hoo.htm c:\temp\hoo.new.htm
FtpDriver -upload ftp://woo/hoo.htm -password xxxxx -local c:\temp\hoo.new.htm
This is an old FtpDriver program I use for purposes like this: http://cheeso.members.winisp.net/srcview.aspx?dir=ftp
Since that tool was written, the FtpWebRequest was added to the .NET Framework; if you wrote that tool now, you'd use that. But the old program I linked to, still works.
Why you need a program: The built-in FTP for Windows is not scriptable. It's a user-interactive console program, which means you have to type things into it, in order to get it to upload or download. It is not possible to automate with cmd.exe programs or commands like echo. So you need that external FTP capability.
If you're willing to get away from batch, then Powershell is a good idea.
精彩评论