将文件从一个 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%"
如果您还有其他问题,请告诉我!
处理此问题的最直接方法是使用 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 }"
Windowsftp.exe
命令行客户端中有rename
command:
rename oldname newname
因此在您的特定批处理文件中:
"%_ScriptFile%" echo rename file.txt %_NewRemoteFolder%/file.txt
虽然在您的问题中看到 _Filename=*.*
,但实际上您似乎想要移动所有文件。使用 Windows ftp.exe
是不可能的,至少不容易。 rename
命令不支持通配符。
您必须根据下载文件列表动态生成脚本文件,并为每个文件使用单独的 rename
命令。
或者在 renaming/moving.
时使用支持通配符的不同命令行 FTP 客户端
例如 WinSCP scripting 批处理文件如下:
winscp.com /log=winscp.log /command ^
"open ftp://username:password@example.com" ^
"cd %_RemoteFolder%" ^
"mv *.* %_NewRemoteFolder%/" ^
"exit"
详情见:
(我是WinSCP的作者)
大家早上好,
我有一个任务需要自动执行从 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%"
如果您还有其他问题,请告诉我!
处理此问题的最直接方法是使用 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 }"
Windowsftp.exe
命令行客户端中有rename
command:
rename oldname newname
因此在您的特定批处理文件中:
"%_ScriptFile%" echo rename file.txt %_NewRemoteFolder%/file.txt
虽然在您的问题中看到 _Filename=*.*
,但实际上您似乎想要移动所有文件。使用 Windows ftp.exe
是不可能的,至少不容易。 rename
命令不支持通配符。
您必须根据下载文件列表动态生成脚本文件,并为每个文件使用单独的 rename
命令。
或者在 renaming/moving.
时使用支持通配符的不同命令行 FTP 客户端例如 WinSCP scripting 批处理文件如下:
winscp.com /log=winscp.log /command ^
"open ftp://username:password@example.com" ^
"cd %_RemoteFolder%" ^
"mv *.* %_NewRemoteFolder%/" ^
"exit"
详情见:
(我是WinSCP的作者)