是否可以安全地定期轮询外部FTPS(或SFTP)服务器,并使用标准Windows Server 2012function在本地复制/移动文件?
我想象使用调度程序来进行轮询/移动,但有没有能力将FTPS / SFTP添加到组合中?
我遇到的唯一指导是把服务器变成一个FTPS服务器,但不知道如何使用操作系统的FTPS客户端…如果有的话。
谢谢
Windows中没有FTPS和SFTP客户端(任何版本)。
内置的Windows ftp.exe支持普通的未encryption的FTP。 而且,它仅支持活动的FTP模式,当连接到防火墙或NAT后面的服务器时,什么使得它非常无用。
您需要使用第三方客户端。
例如,使用WinSCP FTP / SFTP客户端 ,可以使用以下batch file轮询FTPS服务器:
winscp.com /command ^ "open ftps://user:[email protected]/" ^ "get /path/file c:\path\" ^ "exit"
对于SFTP也是如此:
winscp.com /command ^ "open sftp://user:[email protected]/ -hostkey=""ssh-rsa 2048 xx:xx:...""" ^ ...
请参阅使用WinSCP编写脚本的指南 。
然后只需使用Windows Scheduler安排脚本 。
(我是WinSCP的作者)
您还可以使用PowerShell脚本中的.NET框架中的FtpWebRequest类。 它支持FTPS(但不支持SFTP)。 有关详细信息,请参阅@TessellatingHeckler的答案 。
看起来您可以使用标准的Windows工具,使用PowerShell中的.Net Framework的FTPWebRequest类和EnableSsl属性来启用FTPS。
这里有一个例子: https : //stackoverflow.com/q/1279041/478656其中包括代码(我还没有testing):
# Create an FTPWebRequest object to handle the connection to the FTP server $ftprequest = [System.Net.FtpWebRequest]::Create($sourceuri) # Set the request's network credentials for an authenticated connection $ftprequest.Credentials = New-Object System.Net.NetworkCredential($username,$password) # Set FTPWebRequest method to ListDirectory $ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::ListDirectory $ftprequest.EnableSsl = $True $ftprequest.UseBinary = $False $ftprequest.UsePassive = $True $ftprequest.KeepAlive = $False $ftpresponse = $ftprequest.GetResponse() Write-Out $ftpresponse.StatusCode Write-Out $ftpresponse.StatusDescription
我会考虑将UseBinary更改为$ true,然后使用DownloadFile()方法 。
然后按照您的build议从Task Scheduler中调用脚本。