FTP 'rename' command to move remote files

2019-06-13 05:28发布

问题:

I'm writing a *.bat file (Windows) in which I use FTP commands to get remote files back on a local machine. The remote directory includes a archive subdirectory in which I want to move the files once they are downloaded on the local machine.

My script in the *.bat file:

ftp -v -i -s:GET_FILES_FTP.txt

My script in GET_FILES_FTP.txt:

open example.com
username
password
lcd S:\
lcd repository/files
mget *.txt
rename *.txt archive/
disconnect
bye

Note that hostname, username and password are not those I use for real!

The TXT files are downloaded properly on the local machine.

The problem is that rename *.txt archive/ is not interpreted and the files do not move to the archive file. I the command window, I get a directory not found error message. I can't find extra information better than this doc.

Any idea on how to move the files?

回答1:

The rename command of the Windows ftp.exe does not support wildcards.

You would have to dynamically generate a script file based on a list of downloaded files with a separate rename command for each file.


Or use a different command-line FTP client that supports wildcards when renaming/moving.

For example with WinSCP scripting the batch file would be like:

winscp.com /log=winscp.log /command ^
    "open ftp://username:password@example.com" ^
    "lcd S:\" ^
    "lcd repository\files" ^
    "get *.txt" ^
    "mv *.txt archive/" ^
    "exit"

For details see:

  • mv command
  • Converting Windows FTP script to WinSCP FTP script

(I'm the author of WinSCP)