Sars! Posted December 21, 2007 Share Posted December 21, 2007 (edited) Hey guys It's been a while...I would be happy if anyone could help.I need a program in command prompt (a batch file I mean ofcourse), which does this:Extract a registry file out of registry, and automatically upload it to an ftp server, in a map on the ftp server, which has the date as name.This is what I got so far:REG EXPORT HKEY_LOCAL_MACHINE\BLABLABLA C:\BLABLABLA.REGftpopen ftp.mysite.comsars@mysite.commypasswordput c:\BLABLABLA.regbyequitOfcourse it doesn't work, because the username and password aren't typed in manually. I don't think it is possible with the echo command, and it's definately not possible with the print command.And how can you make a map on the ftp server with the current time, in which the reg file will be placed?Any help appreciated.Grtz,SaRs!EDIT:I found those two which may help:@echo offecho.##################echo.# #echo.# Uploading File #echo.# #echo.##################set user=YOUR_USERNAME_GOES_HEREset pass=YOUR_PASS_GOES_HEREset srvr=YOUR_SERVER_GOES_HEREecho.open %srvr%>%temp%\sendtoftp.logecho.%user%>>%temp%\sendtoftp.logecho.%pass%>>%temp%\sendtoftp.logecho.BINARY>>%temp%\sendtoftp.logecho.put %1>>%temp%\sendtoftp.logecho.bye>>%temp%\sendtoftp.logftp -s:%temp%\sendtoftp.logdel %temp%\sendtoftp.loghttp://www.msfn.org/board/index.php?showto...mp;hl=batch+ftpEDIT2:Another problem I have are the spaces in the registry paths. How to write them in ur batch file? Edited December 21, 2007 by Sars! Link to comment Share on other sites More sharing options...
Mordac85 Posted December 21, 2007 Share Posted December 21, 2007 How about something like this?@echo offsetlocal:: Create the date and time elements.For /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do ( For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do ( set dow=%%i set %%a=%%j set %%b=%%k set %%c=%%l set h1=%%m set m1=%%n set s1=%%o ))Set PRE=%dd%-%mm%-%yy%:: Export the key(s)REG EXPORT HKLM\BLABLABLA %~dp0%PRE%_BLABLABLA.reg:: Build the ftp command fileecho [UserName]> %~dp0send2ftp.txtecho [Passwd]>> %~dp0send2ftp.txtecho prompt n>>%~dp0send2ftp.txtecho put %~dp0%PRE%_BLABLABLA.reg>> %~dp0send2ftp.txtecho bye >> %~dp0send2ftp.txt:: Send the fileftp -s:%~dp0send2ftp.txt [ftp server]:: Delete the command filedel %~dp0send2ftp.txtendlocal Link to comment Share on other sites More sharing options...
Sars! Posted December 22, 2007 Author Share Posted December 22, 2007 (edited) What does this stand for:%~dp0Thanx a heaps,SaRs!EDIT: This is my current code:@echo offFor /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do ( For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do ( set dow=%%i set %%a=%%j set %%b=%%k set %%c=%%l set h1=%%m set m1=%%n set s1=%%o ))Set PRE=%dd%-%mm%-%yy%REG EXPORT HKEY_LOCAL_MACHINE\BABLA.reg C:\%~dp0%PRE%_systemlog.txt@echo offset user=...set pass=...set srvr=...@echo offecho.open %srvr%>>%temp%\sendtoftp.logecho.%user%>>%temp%\sendtoftp.logecho.%pass%>>%temp%\sendtoftp.logecho.BINARY>>%temp%\sendtoftp.logecho.put C:\%~dp0%PRE%_systemlog.txt>>%temp%\sendtoftp.logecho.bye>>%temp%\sendtoftp.logftp -s:%temp%\sendtoftp.logdel %temp%\sendtoftp.logThe problem is that, if u open the .txt file after having downloaded it from the server, it displays a lot of strange chinese symbols. I tried both with Binary and not-binary sending. Both failed...Any suggestions?EDIT: And if two files are made on one day, one of them is overwritten. Maybe putting a time stamp on them too would help?Thx a heaps for the help offered already,SaRs! Edited December 22, 2007 by Sars! Link to comment Share on other sites More sharing options...
Yzöwl Posted December 22, 2007 Share Posted December 22, 2007 I'd like to make a suggestion.Try to use yyyy-mm-dd or at least yy-mm-dd it will help with standard sorting methods and follow the ISO 8601 standard format.You dont want file 11-05-2006 to show before 16-03-2005 and 21-01-2007 for example! Link to comment Share on other sites More sharing options...
Mordac85 Posted December 22, 2007 Share Posted December 22, 2007 %~dp0 expands to the current directory, so C:\ in front of it is not needed. As for multiple files, just modify the time stamp with the time as needed since we already have the entire time defined. I picked up this snippet from WindowsITPro and it's explained in detail here. And Yzöwl's idea makes a lot of sense if you ever have to go back and sort through the data.I didn't think about it before but the exported reg file is unicode, and your ftp server must be doing some kind of translation/conversion on it. But an extra step converting it to std ASCII solves the problem.@echo offsetlocalFor /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (set dow=%%iset %%a=%%jset %%b=%%kset %%c=%%lset h1=%%mset m1=%%nset s1=%%o)):: Add the time to the stampSet PRE=%dd%-%mm%-%yy%_%hh%-%min%-%ss%REG EXPORT HKEY_LOCAL_MACHINE\BABLA.reg %temp%\dump.regtype %temp%\dump.reg>%~dp0%PRE%_systemlog.txtdel %temp%\dump.regset user=...set pass=...set srvr=...echo open %srvr%>>%temp%\sendtoftp.logecho %user%>>%temp%\sendtoftp.logecho %pass%>>%temp%\sendtoftp.logecho put %~dp0%PRE%_systemlog.txt>>%temp%\sendtoftp.logecho bye>>%temp%\sendtoftp.logftp -s:%temp%\sendtoftp.logdel %temp%\sendtoftp.logendlocalI'd also recommend keeping the setlocal/endlocal lines so you don't keep the unnecessary variables around in the environment. Run your batch as is and then type 'set' at the command prompt to see what I mean. Link to comment Share on other sites More sharing options...
Yzöwl Posted December 22, 2007 Share Posted December 22, 2007 I didn't think about it before but the exported reg file is unicode, and your ftp server must be doing some kind of translation/conversion on it. But an extra step converting it to std ASCII solves the problem.<snip>REG EXPORT HKEY_LOCAL_MACHINE\BABLA.reg %temp%\dump.regtype %temp%\dump.reg>%~dp0%PRE%_systemlog.txtdel %temp%\dump.regYou can ignore all that if you use regedit to create the registry file in the first instanceREGEDIT/A %~dp0%PRE%_systemlog.txt HKEY_LOCAL_MACHINE\BABLA Link to comment Share on other sites More sharing options...
Sars! Posted December 23, 2007 Author Share Posted December 23, 2007 One more question:What about spaces in the Registry path:For exampleHKEY_LOCAL_MACHINE\BLA BLA\BLABLABLA.regNow, when writing that into "" or even [] it doesn't work in command prompt.Any help?Grtz,SaRs!ps: U guys are like awesome Link to comment Share on other sites More sharing options...
Yzöwl Posted December 23, 2007 Share Posted December 23, 2007 If you are using my regedit example then the following should work exactly as expected.REGEDIT/A %~dp0%PRE%_systemlog.txt "HKEY_LOCAL_MACHINE\BLA BLA\BLABLABLA" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now