如何使用批处理文件SFTP文件?

时间:2018-02-12 17:38:04

标签: ftp sftp winscp windows-scheduler

我们需要通过SFTP将文件从一台服务器传输到另一台服务器。(作业调度程序)

目前通过FTP进行转移。下面是我们用来传输fies的脚本。

for /f "tokens=1,2" %%u in ('date /t') do set d=%%v
set datestr=%d:~6,4%%d:~0,2%%d:~3,2%
rem IF %time:~0,1% GEQ 1 ( set timestr=%time:~0,2%%time:~3,2% ) else ( set timestr=0%time:~1,1%%time:~3,2% )
set timestr=0%time:~1,1%%time:~3,2%
echo %datestr%_%timestr%

echo open ac8b16-a13.no.eri.us >> \\MG2PLK\INPUTPATH\Excel\Important\WDESYMPHONY.txt
echo user username password >> \\MG2PLK\INPUTPATH\Excel\Important\WDESYMPHONY.txt
echo put \\MG2PLK\OutPut\MA-Operation\Extraction\WDESymphony.txt  /dstage/dsdata/External_Input_Files/sympttkt/WDESymphony_%datestr%%timestr%.txt >> \\MG2PLK\INPUTPATH\Excel\Important\WDESYMPHONY.txt
echo put \\MG2PLK\OutPut\MA-Operation\Extraction\sympday-modified.txt  /dstage/dsdata/External_Input_Files/sympttkt/sympday-modified_%datestr%%timestr%.txt >> \\MG2PLK\INPUTPATH\Excel\Important\WDESYMPHONY.txt
echo ! copy /Y \\MG2PLK\OutPut\MA-Operation\Extraction\WDESymphony.txt \\MG2PLK\OutPut\MA-Operation\WDESymphony.txt >> \\MG2PLK\INPUTPATH\Excel\Important\WDESYMPHONY.txt
echo ! copy /Y \\MG2PLK\OutPut\MA-Operation\Extraction\sympday-modified.txt \\MG2PLK\OutPut\MA-Operation\sympday-modified.txt >> \\MG2PLK\INPUTPATH\Excel\Important\WDESYMPHONY.txt
echo close >> \\MG2PLK\INPUTPATH\Excel\Important\WDESYMPHONY.txt 
echo bye >> \\MG2PLK\INPUTPATH\Excel\Important\WDESYMPHONY.txt

Date /T >> \\MG2PLK\INPUTPATH\Excel\Important\WDESYMPHONY.log
Time /T >> \\MG2PLK\INPUTPATH\Excel\Important\WDESYMPHONY.log
C:\winnt\system32\ftp.exe -n -s:WDESYMPHONY.txt >> WDESYMPHONY.log

安装了Winscp和genarated公钥,并根据谷歌搜索将其分享给另一个服务器团队。 并且他们已将公钥添加到例外列表中。

生成计划脚本会遇到麻烦,请您帮忙我如何将此FTP更改为SFTP以传输文件。提前谢谢。

尝试过的方法:

echo open sftp://ftp_user:password@ftp.MyFTPSite.com -hostkey="1234" >> ftpcmd.dat
echo put c:\directory\%1-export-%date%.csv >> ftpcmd.dat
echo exit >> ftpcmd.dat
winscp.com /script=ftpcmd.dat
del ftpcmd.dat

尝试了上述方法,但面临语法问题。没有密码

挣扎于密码的语法

0 个答案:

没有答案