?
Solved

Daily change of Default FTP folder name

Posted on 2009-04-21
15
Medium Priority
?
961 Views
Last Modified: 2013-12-02
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?
0
Comment
Question by:techsedge
  • 5
  • 5
  • 3
13 Comments
 
LVL 14

Expert Comment

by:theras2000
ID: 24200264
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.
0
 
LVL 14

Expert Comment

by:theras2000
ID: 24200280
For the day of the month, you can use this variable.... %date:~4,2%
0
 
LVL 1

Author Comment

by:techsedge
ID: 24200455
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!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Expert Comment

by:theras2000
ID: 24200837
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

0
 
LVL 1

Author Comment

by:techsedge
ID: 24200997
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.
0
 
LVL 14

Assisted Solution

by:theras2000
theras2000 earned 400 total points
ID: 24203192
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.
c:
cd \photos
md %date:~10,4%%date:~7,2%%date:~4,2%

Open in new window

0
 
LVL 51

Accepted Solution

by:
Steve Bink earned 1600 total points
ID: 24221194
Use adsutil to do it.

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d3df4bc9-0954-459a-b5e6-7a8bc462960c.mspx

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.
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 24221203
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.
0
 
LVL 1

Author Comment

by:techsedge
ID: 24229939
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?
0
 
LVL 14

Expert Comment

by:theras2000
ID: 24230267
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.
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 24230713
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

0
 
LVL 1

Author Comment

by:techsedge
ID: 24233252
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

0
 
LVL 1

Author Comment

by:techsedge
ID: 24236536
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

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question