1.

Solve : ftpcmd with dynamic names?

Answer»

Hello,

I use this ftpcmd:

open mywebserver.com
usrname
password
cd httpdocs/mp3
put "C:\files\20062011221.mp3"
QUIT

but 20062011221.mp3 is dynamic. DDMMYYYYHH1 (The one is always the same).mp3
I want to upload every day this mp3 file with a SCRIPT but the name of this file is everyday different

How to solve this problem?easy!!
Create a text file with your commands in it and call FTP -s filename
where filename is the file you stored your commands

Id suggest you put in a bin command before the upload, otherwise you run the risk of stripping off the bit 7 from every mp3 (makes for interesting effects on photos)THANKS for your reply, but that's just what I'm doing. The problem is that I don't know to handle a dynamic file name.

The name of the mp3 is every day different. I can't use "C:\files\20062011221.mp3" because the name changes every day. It should be %D%M%Y%H1.mp3 or something like that.

Is there anyone who knows this?The date and time format is local to each machine. Without knowing that, we can only guess at a solution. For more specific code, please run echo %date% and echo %time% at the command line and post the results.

This little snippet will work if the date format is dow mm/dd/yyyy and the time format is hh:mm:ss.ms You might be able to use it as a template.

Code: [Select]@echo off
setlocal

set dt=%date:~7,2%%date:~4,2%%date:~10,4%%time:~0,2%1
set dt=%dt: =0%

(
echo open mywebserver.com
echo usrname
echo password
echo cd httpdocs/mp3
echo BINARY
echo put "C:\files\%dt%.mp3"
echo quit
) > script.txt

ftp -s script.txt

Good luck.
Thanks. This is exactly what I need.

Is it also possible to give the file a suffix? So 20062011221.mp3 will be 20062011221-done.mp3 on my SERVER?Glad it helped.

Quote

Is it also possible to give the file a suffix? So 20062011221.mp3 will be 20062011221-done.mp3 on my server?

Why not try renaming the file?

Code: [Select]ren C:\files\%dt%.mp3 %dt%-done.mp3

Suggest doing this after the ftp command is complete. If the ftp command returns an errorlevel you can condition the ren in case the upload fails.



Discussion

No Comment Found