Link to home
Start Free TrialLog in
Avatar of techsedge
techsedgeFlag for United States of America

asked on

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?
Avatar of theras2000
theras2000
Flag of United States of America image

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%
Avatar of techsedge

ASKER

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?
Thanks!
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

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.
SOLUTION
Avatar of theras2000
theras2000
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
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)
  ":21:"
 
ServerSize                      : (INTEGER) 1
AllowAnonymous                  : (BOOLEAN) False
Win32Error                      : (INTEGER) 0
[/MSFTPSVC/1/ROOT]

Open in new window

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

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
MD %VAR% 
CSCRIPT C:\Inetpub\AdminScripts\adsutil.vbs SET MSFTPSVC/1/ROOT/Path %VAR%
AT 00:00 "M:\setcamdir.cmd"

Open in new window