Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 批处理文件将文件从一个FTP文件夹移动到同一FTP中的另一个文件夹?_File_Batch File_Cmd_Ftp_Transfer - Fatal编程技术网

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

File 批处理文件将文件从一个FTP文件夹移动到同一FTP中的另一个文件夹?,file,batch-file,cmd,ftp,transfer,File,Batch File,Cmd,Ftp,Transfer,大家早上好 我有一个任务,我需要自动化一个过程,从FTP站点下载文件,用SQL处理文件,然后将FTP站点上的文件移动到同一FTP站点上的另一个文件夹 前两部分我已经记下来了,但是将FTP上的文件移动到同一FTP上的另一个文件夹的部分让我绊倒了 谁能给点建议吗 这就是我目前拥有的: @Echo Off Set _FTPServerName=SERVER HERE Set _UserName=LOGIN HERE Set _Password=PASSWORD HERE Set _RemoteFold

大家早上好

我有一个任务,我需要自动化一个过程,从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 }"
在Windows
ftp.exe
命令行客户端中有:

rename oldname newname

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

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

虽然在您的问题中看到了
\u Filename=*.
,但实际上看起来您想要移动所有文件。这在Windows
ftp.exe中是不可能的,至少不容易做到。
rename
命令不支持通配符

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


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

例如,与批处理文件类似:

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


(我是WinSCP的作者)

您的客户端和FTP主机的操作系统是什么?@lit客户端是Windows 10,FTP主机是Windows Server 2012没有移动命令。您需要下载这些文件,然后将它们上载到另一个文件夹。@squashman这正是我害怕的!感谢您的确认:)我不认为您可以使用FTP中的重命名命令将文件移动到另一个目录,但显然您可以。嘿@lit非常感谢你的回复。您知道PowerShell是预装的还是需要安装和配置的?另外,您提供的代码是否可以在批处理文件中执行?我相信PowerShell预装在Windows 10和Server 2012上。您可能必须配置PowerShell远程处理。这如何连接到服务器上的FTP服务?身份验证到哪里去了?这个答案并没有回答这个问题。问题是关于FTP。答案是关于使用Windows PowerShell进行远程访问。这是两种完全不相关的技术。我知道这对OP有帮助,但这并不意味着答案是正确的。答案至少应该提到,它使用了OP要求的另一种技术。嘿@Martin Prikryl非常感谢你的回复!我只是想说,我使用了你的另一篇文章,使用WinSCP来帮助我测试的另一件事情,它是phenominal,非常感谢!