Daily change of Default FTP folder name

Hello -
I have an old xp machine I am using as an FTP server (IIS). I have security cameras that will deposit small .jpg's to whatever I set the default to. This works fine except that I must manually change the default directory name every other day in order to keep the number of files in a given folder to a reasonable amount (say less than 80,000 files). This is cumbersome, but I am not going to switch to a camera specific software solution for a while yet. (not even the free solutions)
Currently, I am simply pointing the default folder to a new one that is different. I have folder names that go from \1 thru \20 and then get reused.
Can a script be run to automate this?
Who is Participating?
Steve BinkConnect With a Mentor Commented:
Use adsutil to do it.


The service root you need is MSFTPSVC.  Find the identifier for the target site (available in IIS in the "Identifier" column).  The attribute you want to change is /ROOT/Path.  So:

cscript c:\inetpub\adminscripts\adsutil.vbs SET MSFTPSVC/1/ROOT/Path c:\inetpub\ftproot

That commands sets the home directory of the default FTP site (identifier 1) to c:\inetpub\ftproot.  From here, it should be simple to engineer a script to replace the path with one referencing the day/date.
Hmmm.  Could we make it 31 folders?  How bout this plan:
Always send the files to a folder called today, and make this the default FTP folder too.  Each day a scheduled task runs a batch file that moves the files from today to a numbered folder, based on the day of the month.
For the day of the month, you can use this variable.... %date:~4,2%
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

techsedgeAuthor Commented:
The cameras blindly send to the FTP server's IP address, so that's why I want to change the default FTP folder. Yes it would be nice to use the date as a folder name. I think this probably is going to require some sort if vbscripting maybe?
Nah it really is just a simple batch file.

First create the 31 folders e.g. c:\photos\1, c:\photos\2 etc etc
Create your batch file somewhere, with the code attached below.
Create a Scheduld task in Control panel, point it to the batch file, and make it run daily at 11:55pm.
Then just set the default FTP folder to c:\photos\temp

move c:\photos\temp\*.* c:\photos\%date:~4,2%

Open in new window

techsedgeAuthor Commented:
I see what you are saying now. Move the files to a different folder each day. What I was asking for was to have the home directory location change every day. It would be like an instant switch over - currently I go to the IIS\FTP mmc and manually change the FTP home directory to the next higher directory.  Although your idea does make sense, here is more what I had in mind.
It would be great if someone could write a script or whatever that would:
Create a new directory each day, named to be yyyymmdd
Change the default FTP directory in IIS to reflect the newly created folder.
theras2000Connect With a Mentor Commented:
Someone out there might know how to do it, but not me.  The default FTP dir is probably saved somewhere in a file or a registry entry, and someone might find a way of editing that for you on a daily schedule.
Really, I think it would be overengineering this solution.  My way would be much easier.
But maybe there's a particular reason why you don't want the default FTP dir to be the same every day.
My way can create the unique folders like yyyymmdd.  See code.
cd \photos
md %date:~10,4%%date:~7,2%%date:~4,2%

Open in new window

Steve BinkCommented:
FWIW, I agree with theras2000.  Unless you have a pressing reason to not use the same directory, it is better to relocate the files daily than to change your FTP root daily.  With WSH, you can easily script a procedure to move the files from the FTP root to their appropriate daily folder, and maintain a log of those file management actions.  While adsutil will work for what you want to do, I do not agree that it is the best solution.
techsedgeAuthor Commented:
I really don't want to move that many small files (>50000) on a daily basis - That drive gets too fragmented as it is. In my mind that's a valid reason - but? I like the adsutil idea a lot. Can the path accept an environment variable, and if so, maybe set the date within the same batch file?
I'll let reoutinet answer that adsutil question.  But really, do you realise that when a file changes path in NTFS, the change is extremely small?  The pointers to the file change, but the actual file occupies the same portion of harddrive that it was before.  The only thing that changes is the address of the 1st fragment.  All the rest stay the same.  If you don't believe me, try copying a 100MB folder to a thumb drive vs moving it to another folder on your C:. Or heck just rename a sub-folder.  See how quick it is.
Steve BinkCommented:
Again, theras2000 is correct.  If you are moving a file from one directory to another on the same drive, there is no additional fragmentation.  The actual file data is not touched at all, rather the meta-data of the file is changed to reflect the new logical location.

As far as using environment variables, you can use whatever you want to construct the command line for adsutil.  That's what batch and WSH are for.  The example below was generated on just a command line.  You could do more complicated construction inside a batch file, and you could do just about anything you want to in WSH.
C:\Users\luser>set stuff=i*
C:\Users\luser>dir %stuff%
 Volume in drive C has no label.
 Volume Serial Number is 5060-5786
 Directory of C:\Users\luser
04/13/2009  10:55 PM    <DIR>          .imibrowser
02/26/2009  09:10 PM            13,524 index.html
               1 File(s)         13,524 bytes
               1 Dir(s)  391,570,219,008 bytes free
C:\Users\luser>set stuff=MSFTPSVC/1
C:\Users\luser>cscript c:\inetpub\adminscripts\adsutil.vbs ENUM %stuff%
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
KeyType                         : (STRING) "IIsFtpServer"
ServerState                     : (INTEGER) 2
ServerComment                   : (STRING) "Default FTP Site"
ServerBindings                  : (LIST) (1 Items)
ServerSize                      : (INTEGER) 1
AllowAnonymous                  : (BOOLEAN) False
Win32Error                      : (INTEGER) 0

Open in new window

techsedgeAuthor Commented:
Here is what I ended up with, which seems to work OK. If you know of a reason why this will cause problems, please let me know.

1 - Set the yyyymmdd to a system variable
2 - Create the directory, based on newly created variable
3- Change the default FTP folder to the newly created directory
4- Restart the task for the next day using AT, running as system.

rem setcamdir.cmd - create new folder for cameras to dump to each day.
setx camdir %date:~10,4%%date:~4,2%%date:~7,2% -m
md M:\%camdir%
cscript c:\inetpub\adminscripts\adsutil.vbs SET MSFTPSVC/1/ROOT/Path M:\%camdir%
at 00:00 "M:\setcamdir.cmd"

Open in new window

techsedgeAuthor Commented:
The solution doesn't work as System with no user logged in. The cmd file didn't have access to the system variable that setx created. This way works good on fresh boot with no user logged in - without the need for Setx, by creating the date as a temporary variable.

REM - setcamdir.cmd - create a daily date-named dump directory
REM - change the FTP root to use the newly created directory
REM - set to run as system, no user need be logged in
FOR /F "TOKENS=2-4 DELIMS=/- " %%A IN ('DATE/T') DO SET VAR=M:\%%C%%A%%B
CSCRIPT C:\Inetpub\AdminScripts\adsutil.vbs SET MSFTPSVC/1/ROOT/Path %VAR%
AT 00:00 "M:\setcamdir.cmd"

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.