2017-10-16 99 views
0

早上好一切,将文件从一个FTP文件夹移动到同一FTP中的另一个文件夹的批处理文件?

我有,我需要自动化,我们从FTP站点下载文件的过程的任务,该文件是在SQL处理,然后在FTP站点上的文件移动到另一个文件夹在同一个FTP站点上。

我已经倒下了前两部分,但将FTP上的文件移动到同一FTP上的另一个文件夹的部分让我失望。

任何人都可以请提供一些建议吗?

这是我目前有:

@Echo Off 
Set _FTPServerName=SERVER HERE 
Set _UserName=LOGIN HERE 
Set _Password=PASSWORD HERE 
Set _RemoteFolder=FILES FROM 
Set _NewRemoteFolder=FILES TO 
Set _Filename=*.* 
Set _ScriptFile=ftp1 

:: Create script 
"%_ScriptFile%" Echo open %_FTPServerName% 
"%_ScriptFile%" Echo %_UserName% 
"%_ScriptFile%" Echo %_Password% 
"%_ScriptFile%" Echo cd %_RemoteFolder% 
"%_ScriptFile%" prompt 

:: Run script 
ftp -s:"%_ScriptFile%" 
Del "%_ScriptFile%" 

请让我知道,如果您还有其他问题!

+0

客户端的操作系统和FTP主机的操作系统是什么? – lit

+0

@lit客户端是Windows 10,FTP主机是Windows Server 2012 –

+0

没有移动命令。您需要下载这些文件,然后将它们上传到其他文件夹中。 – Squashman

回答

2

有在Windows ftp.exe命令行客户端rename command

rename oldname newname 

因此,在特定的批处理文件:

"%_ScriptFile%" echo rename file.txt %_NewRemoteFolder%/file.txt 

虽然看到_Filename=*.*我你的问题,它看起来像你想要移动所有文件。这对于Windows ftp.exe来说是不可能的,至少不容易。 rename命令不支持通配符。

您必须根据每个文件的单独rename命令,基于下载文件列表动态生成脚本文件。


或者在重命名/移动时使用支持通配符的其他命令行FTP客户端。

例如与WinSCP scripting批处理文件将是这样的:

winscp.com /log=winscp.log /command^
    "open ftp://username:[email protected]"^
    "cd %_RemoteFolder%"^
    "mv *.* %_NewRemoteFolder%/"^
    "exit" 

有关详细信息,请参阅:

(我是作者的WinSCP)

0

处理此问题的最直接方法是使用PowerShell。这将使文件复制发生在FTP主机上,而不需要数据在写回到服务器之前到达客户端。

Invoke-Command -ComputerName FTPHOST -ScriptBlock { Move-Item -Path C:\dir1\thefile.txt -Destination C:\dir2\thefile.txt } 

您可以从cmd.exe shell运行此操作。

powershell -NoProfile -Command "Invoke-Command -ComputerName FTPHOST -ScriptBlock { Move-Item -Path C:\dir1\thefile.txt -Destination C:\dir2\thefile.txt }" 
+0

嘿@lit非常感谢你的回应。你知道PowerShell是预装还是需要安装和配置的东西吗? –

+0

另外,您提供的代码是否可以在批处理文件中执行? –

+0

我相信PowerShell预先安装在Windows 10和Server 2012上。您可能必须配置PowerShell远程处理。 – lit

相关问题