繁体   English   中英

将文件从一个FTP文件夹移动到同一FTP的另一个文件夹的批处理文件?

[英]Batch file to move files from one FTP folder to another folder in the same 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%"

如果您还有其他问题,请告诉我!

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

rename oldname newname

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

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

尽管在您的问题中看到_Filename=*.* ,但实际上看起来像您要移动所有文件。 Windows ftp.exe不可能做到这一点,至少很难做到。 rename命令不支持通配符。

您将必须根据下载文件列表动态生成脚本文件,并对每个文件使用单独的rename命令。


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

例如,使用WinSCP脚本编写批处理文件将类似于:

winscp.com /log=winscp.log /command ^
    "open ftp://username:password@example.com" ^
    "cd %_RemoteFolder%" ^
    "mv *.* %_NewRemoteFolder%/" ^
    "exit"

有关详细信息,请参见:

(我是WinSCP的作者)

解决此问题的最直接方法是使用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 }"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM