# FTP Batch file Help



## raz (Jul 13, 2002)

Hi Guys

Here's a bit of a challenge for you..i dont know whether this is possible or not in batch file so I am throwing it out to the experts.

I have written a quick batch file which goes out and logs in to an FTP site and using WGET picks up a screensaver file and moves it to a specific folder which the corresponds to the Logon Screensaver location in the registry. in theory all files are named the same and should be applied as the logon screensaver.

My problem is this: It works fine except when i try to schedule it using windows scheduler and the Logon Screensaver is active, the file transfer takes place without a problem and dowloads it locally to a downloads folder. uNfortunately because the Scr file is in use. Xcopy can not overwrite it in the Screensaver location.

Is there a way round this problem:
Perhaps a utility which interupts/unlocks the scr file for the copy to take place. I have tried Unlocker.exe to no avail. or alternatively another way round tis issue.

Cheers
Raz

PS Here's the Code
cd\
del /s /Q c:\NLJKSCR\*.*

cd c:\fileze 
md c:\fileze\Downloads 
Md c:\fileze\Uploads 
md c:\fileze\Logs 
md c:\NLJKSCR

wget --output-file=NLJK.log ftp://ab:[email protected]/jk/NLJK/*.*

xcopy c:\fileze\*.scr c:\fileze\downloads /Y 
Xcopy c:\fileze\*.log c:\fileze\logs /Y

Del c:\fileze\*.scr
del c:\fileze\*.log

xcopy c:\fileze\Downloads\*.scr C:\NLJKSCR /Y 
xcopy c:\fileze\Logs\*.log C:\fileze\uploads /Y

cd c:\fileze\uploads

wput NLJK.log ftp://ab:[email protected]/jk/NLJK/Uploads/

pause

PPS NLJKSCR is the location of the screensaver.


----------



## Squashman (Apr 4, 2003)

Don't think you are going to get around that.

My only solution would be to reboot the computer and run the script at shutdown with a group policy. Don't know if that will work, but it is worth a try.


----------



## wookie2u (May 6, 2007)

I've had similar issues shipping exe's to regional servers... we cooked up an effective, but dangerous solution ...
1. copy the exe's to a whatever.new folders on the target servers beforehand 
2. at 1am on Saturday morning (the end of the FM window) have each server:-
a. disconnect this sever from the network severing ALL connections with extreme prejudice - Danger! Will Robinson, Danger!
b. rename whatever to whatever.old
c. rename whatever.new to whatever 
d. reconnect to the network.

We get away with this little hack because it runs so quickly that any active clients (over-running batch programs or whatever) treat it as a network glitch, and simply resend the "lost" packets. 

We've only had one real problem over a couple of years of releasing this way (about every 3 months). A "permanent" SSL "connection" was smart enough to recognise that it's pier process was not the same process it shook hands with on startup, and therefore refused to talk to it... we solved that by just automatically bouncing the connection on the pier server a minute after the release script. The only problem is remembering to schedule it.


----------



## raz (Jul 13, 2002)

Thanks Wookie

Tried to rename the file but the screensaver is in use so it wont even let me rename it

My only option is to somehow disrupt the Logon Screensaver prior to the copy/rename process.
Is it possible to perhaps send Ctrl ALT DEL in batch file prior to copy file?

Any help would be greatly recieved
Thanks


----------



## wookie2u (May 6, 2007)

Ummm, Nah, I don't think so... I'm at a loss really. The only thing I can suggest is set up a sleeper which waits until the screen saved is deactivated by the user and then do the 'ole swaparooney on the file.


----------



## raz (Jul 13, 2002)

Thanks Anyway mate

unfortunately this PC is locked away in a cupboard as it is primarily used to display Information on plasma screens at 5 location around the country. I though it would be a good idea to simplify the process of remoting in and transfering files to run every two days so i divised a batch file and FTP solution. I guess we'll have to stick with manually remoting in and running the batch file at each machine.

Any other ways this could be achieved apart from Bat files?


----------



## JohnWill (Oct 19, 2002)

The screen saver isn't running if you have some mouse or keyboard activity, right? Why not use AutoIt to create a little script to move the mouse and kill the screensaver in that batch file?


----------



## raz (Jul 13, 2002)

JohnWill said:


> The screen saver isn't running if you have some mouse or keyboard activity, right? Why not use AutoIt to create a little script to move the mouse and kill the screensaver in that batch file?


Thanks JohnWill

Thats interesting idea, i am not too familiar with AutoIT, i have spent most of the afternoon on the website and scripting and cant get it to send CTRL ALT DEL at the Logon screen to interupt the screensaver, Do you know whether this is possible with Auto IT or does autoit need to be logged in to a user account to work?

Any help is as always greatly appreciated

Cheers


----------



## JohnWill (Oct 19, 2002)

It would probably have to be logged into a user account, never tried it without.

Just a question, what's the purpose of the screen saver anyway? I let my systems just set the monitor into power save when I want to "save" the screen.


----------



## raz (Jul 13, 2002)

Thanks johnwill though as much.

i am just trying to simplify an ill-concieved project to allow content to be remotely downloaded to 12 pc with Plasma screens acrross the country rather than to uvnc in every week via internet to load information content manually. initially the idea was powerpoint presentation looping contiously with powerpoint viewer, however the slideshow jumpsout onto desktop after x rotations so not ideal so i came up with the screensaver idea at logon screen for security and it works. Now i would like to automate it and have devised a bat script to log into an ftp server and using wget pull down the files and put them in the screensaver directory. only snag is that when automated the downloads occurs but as the screensaver is active the file can not be copied in the same directory. Bummer


----------



## JohnWill (Oct 19, 2002)

See previous ideas.


----------



## wookie2u (May 6, 2007)

I'd be shocked if autoit (or anything else short of ASM) can simulate the ctrl-atl-del keyboard sequence. It was intended to specifically prevent network programs like your script from logging onto the machine remotely, without the owners consent or knowledge.

It might worth looking on MSDN to see if you can replace the windows logon program with one of your own... the logon form can't be more that a couple of hundred lines of VC++... then you can do whatever you like... careful with that axe though.

keith.


----------



## JohnWill (Oct 19, 2002)

You're right, you can't simulate Ctrl+Alt-Del, however Autoit may still run under the System account. I've never tried it...

OTOH, There's no reason the remote workstations can't be logged in with basically no privileges and accomplish the same task.


----------



## raz (Jul 13, 2002)

JohnWill said:


> You're right, you can't simulate Ctrl+Alt-Del, however Autoit may still run under the System account. I've never tried it...
> 
> OTOH, There's no reason the remote workstations can't be logged in with basically no privileges and accomplish the same task.


Thanks JohnWill and wookie
have tried that and used the screensaver slide deck as the desktop screensaver, the batch file when scheduled works great interupting the screensaver howerver after 10 revolutions of the slide deck screensaver on the non previledged account, it jumps out back into the desktop profile, even setting the screensaver to kick in again at the minimim 1 min is useless as it is meant to be a continious rolling presentation, perhaps there is a way to further reduce the 1 min minimum wait in the registry? is this possible?


----------



## JohnWill (Oct 19, 2002)

I think the solution may be to not actually use a screen saver for the task, it's getting to look like this has problems all over the place.


----------



## raz (Jul 13, 2002)

JohnWill said:


> I think the solution may be to not actually use a screen saver for the task, it's getting to look like this has problems all over the place.


so does life..my friend i guess if it was easy any monkey could do it.....thats why they pay us the big bucks....NOT!!! 

BTW How would you approach this solution, what method would you use? out of interest?

Cheers

Monkey No 1
Raz


----------



## JohnWill (Oct 19, 2002)

My inclination would be to have an application running on the machine that accesses a folder and runs the slide show, it could easily deal with changing the show at that point.


----------



## raz (Jul 13, 2002)

JohnWill said:


> My inclination would be to have an application running on the machine that accesses a folder and runs the slide show, it could easily deal with changing the show at that point.


Thanks, i had touted for a content management system to be developed but the old ...there's no money in the kitty to justify developing a CMS.... chesnut was the excuse. Is there a proprietry software that we could use that you know of? that will perform the function adequately, if i could prove that a test scenario works, i'm sure we could find the money to purchase it.

cheers


----------



## JohnWill (Oct 19, 2002)

Can you convert these PP slides to graphic images? If so, why not almost any slide show application?

Are you saying that PP stops cycling the show after a set number of iterations? Is there any way to fix that? I confess to not having looked for this capability from PP.


----------



## raz (Jul 13, 2002)

HMM interesting idea but would the same problem reappear if the grapic image was in use by the slide show programme and locks the image so it couldnt be overwritten?

yes thats correct PP viewer drops out of Slideshow (which has been encoded to run continiously advancing every 10s) after a good while and stays in on desktop, i tested this overnight, removed the keyboard/mouse and in the morning the desktop was on show!! i am presuming this is the same for powerpoint full version. again the file locking demon rears it head.


----------



## JohnWill (Oct 19, 2002)

It's not a big deal to terminate and restart the slideshow application in a simple batch file, which should solve the issue. It'll be a whole lot easier to manage than trying to fool the screen saver.


----------



## wookie2u (May 6, 2007)

I can't remember if I've already suggested this... forgive me if I'm repeating myself.

If what you're trying to achieve is customised "screen saver" behaviour then perhaps you'd be better of rolling your own screen saver? I just googled "C++ screen saver" and it looks like that path is fairly well traveled. 

I'm thinking you could build a "picture downloader" into the screen saver such that the server would just broadcast "new pictures" over UDP. The client would have to reassemble each picture, and either re-request any lost packets via UDP.

Alternately the server could send a "new picture available" UDP notification, and each client could (using a backoff-n ARQ) socket connect (garanteed delivery) and just download the new pictures.

I wonder how the google screensaver does it? It's open source.

It's an interesting "little" problem, which just keeps growing ;-)

Anyways, I wish you the best of luck with it.

cheers. keith.


----------



## raz (Jul 13, 2002)

Thanks Keith and JohnWill once again, Unfortunately i'm no programmer and C++ or any other language never agreed with me at college hence i chose support and deployment. Maybe its time i dusted off C++ for dummies as it seems that there are no proprietry software for this. perhaps i will try and look into a third party screensaver app and kill that for an update. I Can't find windows once scrnsave.exe, perhaps it may be possible to kill that and restart that in a batch file

Cheers


----------



## JohnWill (Oct 19, 2002)

If I were facing this issue, I think I'd be going for a standard slideshow application that would continually run, and when it came time to change the slides, I'd do the following in a script.

Upload the new slides to a temp folder.
Run a script to kill the slideshow, erase the old slides, move the new slides to the working folder, and restart the slideshow.


----------



## wookie2u (May 6, 2007)

> Unfortunately i'm no programmer and C++ or any other language never agreed with me.

I hear you. C++ never actually agreed with anyone... it just does it's own thing and us programmers just go along with it, smiling and nodding in an utterly hopeless attempt at appearing intelligent. 

All real advances in software engineering over the last 20 years have been made by aliens and small (size 3 ladies) sock puppet named Trevor who lives between the bowl and casing of the washing machine at Lady Flannerty's Home For Stray Cats. Trevor only emerges during a full lunar eclipse to wolf down a couple of cheese burgers and permanently alter the course of human history. Apparently, Tevor gets right off on that wobbly bit at start of every spin cycle.  

Seriously, I'd consider rolling my own picture shower... there can't be more than a couple of hundred lines of code in it (think of that as a Plumbers "I'll be there Tuesday"), and I reckon it'd be easier than dealing with the problems you're facing trying to get windows to do something useful.

keith.


----------



## raz (Jul 13, 2002)

Since my simple question posed such a huge debate and interest, i thought id Post how i got round the problems using batch file scripting. It took a lot of perserverance and testing testing and testing and it seem to work, its been rolled out to our test site for about a week and seem to be working as planned.

Here's what I did....

Two batch files....one that uses wget to log into the FTP server and download the .Scr file to a local folder. This is scheduled to run at 5pm every evening

the second.. a machine start up script that copies the Scr file from the local folder to the screensaver directory.

Hang on..i can hear you all screaming how did i get round the problem of the screensaver locking out...well i added shutdown -r to the botton of the first script to do a restart of the computer and then changed the entry in the registry for the screensaver to kick in after 2mins to allow enough time for the file to be copied over.

so script one picks up the file and dumps it to a local folder then reboots, allowing the second script to copy the screensaver file to the directory....Voilla..2mins later...new screensaver running

Really chuffed at that 

Hope it helps someone

Cheers
Raz

PS Cheers Squashman...for planting the seed that grew and to everyone for watering the idea....(sorry just been doing the gardening this morning  )


----------



## wookie2u (May 6, 2007)

raz,

Glad you had win. I'm smiling. Really. Yep, persistence pays.

It sounds like a rather simple elegant solution. Well done.

And I want to thank you for taking the time to post an outline of the solution, if not the code itself... it makes for a healthy community.

I'd be happy to be of no help to you again any time ;-)

keith.


----------



## raz (Jul 13, 2002)

Cheers guys...i'm just feeling the love here 

if anyone wants the code, i am happy to post/share it and in any potential profit
although it has evolved a bit since we last spoke, it now deposits ftp logs on the server and emails them to me at the end of the cycle. I now use ncftp instead of wget. give me a shout and i'll go thru it.

i still need to lock down a user account to allow the natives to manually run the batch script on the desktop and nothing else, any ideas how this can be achieved?



JohnWill said:


> OTOH, There's no reason the remote workstations can't be logged in with basically no privileges and accomplish the same task.


Johnwill how would i achieve this? Mandatory profiles? and restricted accounts? all i want is the local user to see is a blank desktop with a couple of apps and nothing in start menue except log off. i dont want the local to start hacking the hard work we have done 

Cheers
Raz


----------

