簡體   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