windowsbatch-filecmdftprename

Rename local file before upload to FTP in Windows command-line


I have the following script which does not work for some reason. I need to rename (appending current date) Feed.txt file every day and upload it to FTP. What am I missing?

eco
secret_pwd
ascii
lcd C:\Jobs
rename Feed*.txt Feed_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt
cd Uploads
put Feed_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txt
quit

Solution

  • rename in ftp.exe script renames a file on FTP server.

    While you want to rename a local file. For that you need to use rename command of cmd.exe, not ftp.exe.

    So either move the rename to a batch file that executes your FTP script, if any.

    Or prefix the rename with ! to instruct ftp.exe to escape to cmd.exe.