问题描述
我现在有上在不同位置的CSV文件传送到FTP服务器不同的服务器批处理脚本。我的脚本看起来类似于这样:
I currently have batch scripts on different servers that transfer a csv file to an FTP server at a different location. My script looks similar to this:
echo user ftp_user> ftpcmd.dat
echo password>> ftpcmd.dat
echo put c:\directory\%1-export-%date%.csv>> ftpcmd.dat
echo quit>> ftpcmd.dat
ftp -n -s:ftpcmd.dat ftp.MyFTPSite.com
del ftpcmd.dat
如果我想需要一个安全的传输,是怎么将我的脚本进行更新?
If I wanted to require a secure transmission, is how would my script be updated?
感谢。
推荐答案
首先,确保你明白,如果你需要使用的(= FTPS,按您的文本)或 (按标签已使用)。
First, make sure you understand, if you need to use Secure FTP (=FTPS, as per your text) or SFTP (as per tag you have used).
正如你所说,你可以使用。它支持FTPS和SFTP。
As you have suggested, you can use WinSCP. It supports both FTPS and SFTP.
使用WinSCP赋予,您的批处理文件看起来像(对SFTP):
Using WinSCP, your batch file would look like (for SFTP):
echo open sftp://ftp_user:password@ftp.MyFTPSite.com -hostkey="server's hostkey" >> ftpcmd.dat
echo put c:\directory\%1-export-%date%.csv >> ftpcmd.dat
echo exit >> ftpcmd.dat
winscp.com /script=ftpcmd.dat
del ftpcmd.dat
和批处理文件:
winscp.com /log=ftpcmd.log /script=ftpcmd.dat /parameter %1 %date%
虽然使用WinSCP赋予(尤其是提供命令和 %TIMESTAMP%
语法) ,该批处理文件可以简化为:
Though using all capabilities of WinSCP (particularly providing commands directly on command-line and the %TIMESTAMP%
syntax), the batch file simplifies to:
winscp.com /log=ftpcmd.log /command ^
"open sftp://ftp_user:password@ftp.MyFTPSite.com -hostkey=""server's hostkey""" ^
"put c:\directory\%1-export-%%TIMESTAMP#yyyymmdd%%.csv" ^
"exit"
有关 -hostkey
开关的目的,看到的主机密钥。
For the purpose of -hostkey
switch, see verifying the host key in script.
有关FTPS,更换 SFTP://
中的与 FTPS://
。删除 -hostkey
开关。你还需要知道,如果你想使用( -explicit
开关),或
You may need to add -certificate
switch, if your server's certificate is not issued by a trusted authority.
请参阅从 Ftp.exe的
一个完整的。
您也应该阅读:结果
请注意使用%TIMESTAMP#YYYYMMDD%
而不是%DATE%
:的格式%DATE%
变量的值是特定于语言环境。因此,请确保您测试您真正要使用这个脚本在同一区域的脚本。例如在我的捷克区域设置的%DATE%
解析为 CT 06. 11. 2014
,可能是什么问题时,用作文件名的一部分。
Note to using %TIMESTAMP#yyyymmdd%
instead of %date%
: A format of %date%
variable value is locale-specific. So make sure you test the script on the same locale you are actually going to use the script on. For example on my Czech locale the %date%
resolves to čt 06. 11. 2014
, what might be problematic when used as a part of a file name.
为此WinSCP赋予(5.7及更高版本)支持(区域中性)时间戳格式本身。例如%TIMESTAMP#YYYYMMDD%
解析为 20141106
上的任何区域。
For this reason WinSCP (5.7 and later) supports (locale-neutral) timestamp formatting natively. For example %TIMESTAMP#yyyymmdd%
resolves to 20141106
on any locale.
请参阅
的(我的WinSCP的作者)的
这篇关于使用Windows批处理脚本安全FTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!