简体   繁体   English

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

[英]Batch file to move files from one FTP folder to another folder in the same FTP?

Good morning all, 大家早上好,

I have a task where i need to automate a process where we download files from an FTP site, the files are processed in SQL, and then the files on the FTP site are moved to another folder on that same FTP site. 我有一个任务需要执行一个自动化过程,即从FTP站点下载文件,用SQL处理文件,然后将FTP站点上的文件移动到该FTP站点上的另一个文件夹。

The first two parts i have down but the part of moving the files on the FTP to another folder on the same FTP is tripping me up. 我的前两个部分已关闭,但是将FTP上的文件移动到同一FTP上的另一个文件夹的部分使我绊倒了。

Can anyone please offer some advice? 有人可以提供一些建议吗?

This is what i currently have: 这是我目前拥有的:

@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%"

Please let me know if you have further questions! 如果您还有其他问题,请告诉我!

There's rename command in Windows ftp.exe command-line client: Windows ftp.exe命令行客户端中有rename命令

rename oldname newname

So in your specific batch file: 因此,在您的特定批处理文件中:

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

Though seeing the _Filename=*.* in your question, it actually looks like you want to move all files. 尽管在您的问题中看到_Filename=*.* ,但实际上看起来像您要移动所有文件。 That's not possible with Windows ftp.exe , at least not easily. Windows ftp.exe不可能做到这一点,至少很难做到。 The rename command does not support wildcards. rename命令不支持通配符。

You would have to dynamically generate a script file based on a list of downloaded files with a separate rename command for each file. 您将必须根据下载文件列表动态生成脚本文件,并对每个文件使用单独的rename命令。


Or use a different command-line FTP client that supports wildcards when renaming/moving. 或在重命名/移动时使用支持通配符的其他命令行FTP客户端。

For example with WinSCP scripting the batch file would be like: 例如,使用WinSCP脚本编写批处理文件将类似于:

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

For details see: 有关详细信息,请参见:

(I'm the author of WinSCP) (我是WinSCP的作者)

The most direct way to handle this is to use PowerShell. 解决此问题的最直接方法是使用PowerShell。 This will make the file copy happen on the FTP host without requiring the data to come to your client before being written back to the server. 这将使文件复制在FTP主机上进行,而无需在将数据写回到服务器之前将数据发送到客户端。

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

You can run this from a cmd.exe shell. 您可以从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.

相关问题 windows 批处理文件脚本,用于从文件夹中选择随机文件并将它们移动到另一个文件夹 - windows batch file script to pick random files from a folder and move them to another folder 将文件从文件夹/子文件夹移动到另一个文件夹中的相同文件夹结构 - Move files from folders/subfolders to same folder structure in another folder 将文件从一个ftp传输到另一个ftp - Transfer files from one ftp to another 随机将文件从一个文件夹移动到另一个文件夹? - randomly move files from a folder to another folder? 在Powershell中将X文件从一个文件夹移动到另一个文件夹 - Move X files from one folder to another in Powershell 自动将文件从一个文件夹移动到Google云端硬盘中的另一个文件夹 - Move files automatically from one folder to another in Google Drive PHP:通过FTP打开并显示文件夹中的最新文件 - PHP: Open and show the most recent file from a folder via FTP 将特定文件上传到Java中的文件夹(FTP) - Uploading specific file to a folder (FTP) in java 需要创建一个批处理文件从一个文件夹中随机选择一个文件并复制到另一个文件夹 - Need to create a batch file to select one random file from a folder and copy to another folder 将文件从文件夹移动到文件夹 - Move file from folder to folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM