Jump to content

FileCopy command with encrypted file


skippynz
 Share

Recommended Posts

ive got a script here that is going to be used for backup of a users data from pc to USB hdd and all the encrypted data is copied across ok - however if i run the backup program from a network drive the encrypted files are not copied over..

im just using the filecopy command included in autoit.

is this something that can be sorted out or do i need to do a different command - ie xcopy or something like that ? my preference is to stay with the filecopy command as its lightening quick compared to xcopy or robocopy..

cheers

craig

Link to comment
Share on other sites

SYS

(Show your script)

i would but it 1400 lines long - i just have a query about file copy - i know the script works - ie if i run from usb its flawless as the encrypted files get copied across however if i run it over the network from a network drive it doesnt copy the files over - im guessing it has something to do with the files being decrypted as they come across cause if you sit in the folder where the files are going you see the name and a size of 0 bytes then the file disappears and the next file comes over and same thing - there are 2 files that are not encrypted in the folder in question and they stay there fine - so know there is nothing wrong with my script. just questioning the FILECOPY command and if there is anything that will enable it to decrypt and copy or whatever....

cheers

craig

Link to comment
Share on other sites

hmmm just tried with xcopy and robocopy and the copies dont appear to be working correctly. does the original files in the folder but not files in the sub folders

_rundos('robocopy "'& $current & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '\" ' & $file & ' /np /zb')oÝ÷ Ú«zɲrr~éܶ*'¬r~º&¢w¨~Ø^ì¬êÞjëh×6 
Func ProgressCopy($current, $destination, $UseMultiColour=0, $attrib = "", $overwrite = 1 ,$Run1 = 0 )
    ;FirstTimeRun Get original DirSize and set up Gui
    If $Run1 = 0 Then
        If not FileExists ($Destination) then DirCreate ($Destination); This is why it was failing, the dir did not exist
        $source = $current
        If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1)
        If StringRight($destination, 1) <> '\' Then $destination = $destination & "\"
        $tosearch = $current
        $Overall = DirGetSize($tosearch, 1)
        $OverallQty = $Overall[1]
        $PrCopyGui = GUICreate("Copying Files", 420, 100, -1, 130, BitOR($WS_BORDER, $WS_POPUP), $WS_EX_TOPMOST)
        $Progress0Text = GUICtrlCreateLabel("Please Wait", 10, 5, 400, 20, $SS_LEFTNOWORDWRAP)
        $progressbar1 = GUICtrlCreateProgress(10, 20, 400, 20,$PBS_SMOOTH)
        $Progress1Text = GUICtrlCreateLabel("", 10, 44, 400, 20, $SS_LEFTNOWORDWRAP)
        $progressbar2 = GUICtrlCreateProgress(10, 60, 400, 20, $PBS_SMOOTH)
        $Progress2Text = GUICtrlCreateLabel("", 10, 82, 400, 20, $SS_LEFTNOWORDWRAP)
        GUISetFont(10, 600)
        GUISetState(@SW_SHOW)
        GUICtrlSetData($Progress1Text, "Working Directory " & $tosearch)
        $Run1 = 1
    EndIf
    
    $Size = DirGetSize($current, 3)
    $Qty = $Size[1]
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            $Qty -= 1
            $LocalPercent = 100 - (($Qty / $Size[1]) * 100)
            $OverallQty -= 1
            $overallpercent = 100 - (($OverallQty / $Overall[1]) * 100)
            GUICtrlSetData($Progress0Text, "Total Progress " & Int($overallpercent) & "% completed")
            GUICtrlSetData($progressbar1, $overallpercent)
            GUICtrlSetData($progressbar2, $LocalPercent)
            GUICtrlSetData($Progress2Text, "Copying File " & $file)
            
            If $useMultiColour then 
                GUICtrlSetColor($Progressbar2, _ChangeColour($LocalPercent))
                GUICtrlSetColor($Progressbar1, _ChangeColour($OverallPercent))
            EndIf
            
            _rundos('robocopy "'& $current & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '\" ' & $file & ' /np /zb')
;~          FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file,$overwrite)
;~          FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            DirCreate($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file)
            FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
            GUICtrlSetData($Progress1Text, $current & "\" & $file)
            ProgressCopy($current & "\" & $file, $destination, $UseMultiColour, $attrib, $overwrite,1)
        EndIf
    WEnd
    FileClose($search)
    ;when overall percent = 100 set end gui text, delete gui and reset run1 to 0
    If $overallpercent = 100 Then
        GUICtrlSetData($Progress0Text, "Total Progress 100% completed")
        GUICtrlSetData($progressbar1, 100)
        GUICtrlSetData($progressbar2, 100)
        GUICtrlSetData($Progress2Text, "Done!")
        Sleep(2000)
        GUIDelete($PRCopyGui)
        $Run1 = 0
    EndIf
EndFunc  ;==>ProgressCopy

Func _ChangeColour($start)
    
    $Redness = Int(255 - ($start  / 100 * 512)) 
    If $Redness < 0 Then $Redness = 0
        
    $Greeness = Int(($start  / 100 * 512) - 257) 
    If $Greeness < 0 Then $Greeness = 0
        
    $Blueness = Int(255 - ($Redness + $Greeness))
    
    Return ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness

EndFunc
Edited by craig.gill
Link to comment
Share on other sites

im trying to help heheh but as at the moment my 1 Gig USB drives are still packaged (which i got for $4 each ;) ) so i am unable to test out filecopy

well as its supposed to be a "hack" but it shows how to use xcopy to copy over files onto the USB drive

http://www.usbhacks.com/ i think ehhe didnt read through it just saw xcopy and copy files onto USB drive

CODE

First create an autorun.inf file that looks like this:

[autorun]
icon=lilguy.ico
open=start.bat
action=Click “OK” to enable USB flash drive
shell\open\command=start.bat
oÝ÷ Ù*0{¥
æjwn±ëay«­¢»§¶¸Ìæ«çejËpyé-¡º-èmë¬z»h®éí橦XjØ¨í¡«­¢f­Æ¥*î'Ý¢æåyÉbrG"vrÛ«miÉ0êÞjf¥È¨ºË¬z¸¬jÛ^bh²×)ߢ¹¶*'&j̬µé­ì°Yi®Ún­jGvö§µ¨¡ûayMÚºÚ+ºxZrK(¶­Úîɨ­ê®É%É»­²)Ü{­èî²Û!£§ªk¢è}Ê'qêmÁçh͵îÙÞyÛaĨʰYg¢ØzØZ¶Ø^jëh®éâ÷±yË­zËazËZ®ÖÚµø¥y8b±ø¥x¦§Ú.±ëhvp¢Øb%¡§mæ¶æ¥²[«¦)àm«ø¥yÊ&©Ý±«0zYZ²zØ^r¦jwi®©¶l¦x¦8§+m+0¢é]éi'^{¶°«HjghxºÚ"µÍXÚÈÙÝÛZ[Û]Ð^]

First I create a directory on my USB flash drive. The “%~d0″ here is a Windows variable that you can use which will output the drive from which the script is currently running. So I tell it to create a directory on my Flash drive and to name the directory the computer’s name, this is just in case I am auditing multiple systems. The xcopy command I have here will then start copying any file with a “.doc” extension it finds, it will descend into subdirectories as well as copy the subdirectories in the same tree as the actual “My Documents” directory it is copying from.

This is just a quick example of podslurping and just how simple it really is. However, there are more malicious podslurping tools out there which do a better job of searching for specific files of value, hide themselves better and even run in the background on startup not just loading files to a USB flash drive, but actually sending files offsite either view email, FTP and even VNC.

Edited by Thatsgreat2345
Link to comment
Share on other sites

im trying to help heheh but as at the moment my 1 Gig USB drives are still packaged (which i got for $4 each ;) ) so i am unable to test out filecopy

well as its supposed to be a "hack" but it shows how to use xcopy to copy over files onto the USB drive

http://www.usbhacks.com/ i think ehhe didnt read through it just saw xcopy and copy files onto USB drive

CODE

First create an autorun.inf file that looks like this:

[autorun]
icon=lilguy.ico
open=start.bat
action=Click OK to enable USB flash drive
shell\open\command=start.bat
oÝ÷ Ù*0{¥
æjwn±ëay«­¢»§¶¸Ìæ«çejËpyé-¡º-èmë¬z»h®éí橦XjØ¨í¡«­¢f­Æ¥*î'Ý¢æåyÉbrG"vrÛ«miÉ0êÞjf¥È¨ºË¬z¸¬jÛ^bh²×)ߢ¹¶*'&j̬µé­ì°Yi®Ún­jGvö§µ¨¡ûayMÚºÚ+ºxZrK(¶­Úîɨ­ê®É%É»­²)Ü{­èî²Û!£§ªk¢è}Ê'qêmÁçhÙÞyÛaĨʰYg¢ØzØZ¶Ø^jëh®éâ÷±yË­zËazËZ®ÖÚµø¥y8b±ø¥x¦§Ú.±ëhvp¢Øb%¡§mæ¶æ¥²[«¦)àm«ø¥yÊ&©Ý±«0zYZ²zØ^r¦jwi®©¶l¦x¦8§+m+0¢é]éi'^{¶°«HjghxºÚ"µÍXÚÈÙÝÛZ[Û]Ð^]

First I create a directory on my USB flash drive. The %~d0″ here is a Windows variable that you can use which will output the drive from which the script is currently running. So I tell it to create a directory on my Flash drive and to name the directory the computers name, this is just in case I am auditing multiple systems. The xcopy command I have here will then start copying any file with a .doc extension it finds, it will descend into subdirectories as well as copy the subdirectories in the same tree as the actual My Documents directory it is copying from.

This is just a quick example of podslurping and just how simple it really is. However, there are more malicious podslurping tools out there which do a better job of searching for specific files of value, hide themselves better and even run in the background on startup not just loading files to a USB flash drive, but actually sending files offsite either view email, FTP and even VNC.

um - im not sure you understand what im after - the program is a backup util for the company i work for - we are implimenting EFS file encryption and wanted a way to backup our data - so ive created this script to do the data copy - ie checks for a list of folders then if they are there will backup the data to the USB drive or network share you are running the script from - it works ok on the usb drive but not from the network using the filecopy command in autoit - like i said i think that the network side i things isnt working because the files are being decrypted on the way over the lan - my question is - how do i get the filecopy command working - or will it never work ? so in that case how do i get my above commands for xcopy or robocopy to work - cause at the mo they are creating the folders but not copying the files across. well only 1 folder is coming across - the rest of the files arent... the ones that seem to not be coming across are the ones that are in subfolders....

arrgghh this is painful - any ideas ??????

Link to comment
Share on other sites

hmmm just tried with xcopy and robocopy and the copies dont appear to be working correctly. does the original files in the folder but not files in the sub folders

_rundos('robocopy "'& $current & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '\" ' & $file & ' /np /zb')
I don't know if this will fix your problem or not. I don't have any EFS files on my computer, but when I get to my work I will run a test. I try the code you supply on Post #5, after copy was done it does the original files in the folder but not files in the sub folders. I did the following changes to the script and now works with robocopy.

Replace this line: If StringRight($destination, 1) <> '\' Then $destination = $destination & "\"

for this instead: If StringRight($destination, 1) = '\' Then $destination = StringTrimRight($destination, 1)

robocopy doesn't need the ending backslash for the source or destination folder.

Repalce this line: _rundos('robocopy "'& $current & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '\" ' & $file & ' /np /zb')

for this instead: _rundos('robocopy "'& $current & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '" ' & $file & ' /np /zb')

Edit:

I just run another test.

1) I delete robocopy line and unremark Filecopy and Filesetattrib.

2) Add the following line before Filecopy: ConsoleWrite( $current & "\" & $file & ', ' & $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file & @CRLF)

when I run the script calling the function ProgressCopy('c:\Application_Data', 'c:\temp') and look at the console output in SciTe this is what I get.

c:\Application_Data\Notes\alog4.ntf, c:\temp\\Notes\alog4.ntf

As you can see mark in red it add an extra backslash to all subdirectories, so if you using this function with an unc path (\\sever\share) you going to have an extra backslash which it could be the reason why copying over the network won't work. Try what I suggested above and replace the if statement. This also could be the reason why didn't work with xcopy.

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

I don't know if this will fix your problem or not. I don't have any EFS files on my computer, but when I get to my work I will run a test. I try the code you supply on Post #5, after copy was done it does the original files in the folder but not files in the sub folders. I did the following changes to the script and now works with robocopy.

Replace this line: If StringRight($destination, 1) <> '\' Then $destination = $destination & "\"

for this instead: If StringRight($destination, 1) = '\' Then $destination = StringTrimRight($destination, 1)

robocopy doesn't need the ending backslash for the source or destination folder.

Repalce this line: _rundos('robocopy "'& $current & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '\" ' & $file & ' /np /zb')

for this instead: _rundos('robocopy "'& $current & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '" ' & $file & ' /np /zb')

Edit:

I just run another test.

1) I delete robocopy line and unremark Filecopy and Filesetattrib.

2) Add the following line before Filecopy: ConsoleWrite( $current & "\" & $file & ', ' & $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file & @CRLF)

when I run the script calling the function ProgressCopy('c:\Application_Data', 'c:\temp') and look at the console output in SciTe this is what I get.

c:\Application_Data\Notes\alog4.ntf, c:\temp\\Notes\alog4.ntf

As you can see mark in red it add an extra backslash to all subdirectories, so if you using this function with an unc path (\\sever\share) you going to have an extra backslash which it could be the reason why copying over the network won't work. Try what I suggested above and replace the if statement. This also could be the reason why didn't work with xcopy.

thanks for your reply danny35d - i noticed the problem with my robocopy line and the extra \ but even with removing that it doesnt work - i put in the consolewrite line as you suggested and watched it and its all ok with that command - i just gotta figure out where the problem lies with robocopy

- will look at it some more and post back shortly. cheers

Link to comment
Share on other sites

I'm been testing this at work and the robocopy version is working. I have to add quotes to $file in case that the file name has spaces.

_rundos('robocopy "'& $current & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '" "' & $file & '" /np /zb')

but like you mention on your post it is veryyy slow.

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

I'm been testing this at work and the robocopy version is working. I have to add quotes to $file in case that the file name has spaces.

_rundos('robocopy "'& $current & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '" "' & $file & '" /np /zb')

but like you mention on your post it is veryyy slow.

you are a legend - your post about swapping the \ in the if statement did the trick - its working ok for me now - the reason its slow is cause it has to decrypt the file on the way over to the network drive.

but at least its working and thats all that matters.

thanks for your help - appreciate it...

cheers

craig

Link to comment
Share on other sites

Your welcome, may be this work faster for you. Basically it is the same script with the twist that if FileCopy() function fails it will switch to copy with robocopy or xcopy. Just remark the ConsoleWrite and unremark robocopy or xcopy it is your choice.

Func ProgressCopy($current, $destination, $UseMultiColour=0, $attrib = "", $overwrite = 1 ,$Run1 = 0 )
    ;FirstTimeRun Get original DirSize and set up Gui
    If $Run1 = 0 Then
        If not FileExists ($Destination) then DirCreate ($Destination); This is why it was failing, the dir did not exist
        $source = $current
        If StringRight($current, 1) = '\' Then $current = StringTrimRight($current, 1)
        If StringRight($destination, 1) = '\' Then $destination = StringTrimRight($destination, 1)
        $tosearch = $current
        $Overall = DirGetSize($tosearch, 1)
        $OverallQty = $Overall[1]
        $PrCopyGui = GUICreate("Copying Files", 420, 100, -1, -1, BitOR($WS_BORDER, $WS_POPUP), $WS_EX_TOPMOST)
        $Progress0Text = GUICtrlCreateLabel("Please Wait", 10, 5, 400, 20, $SS_LEFTNOWORDWRAP)
        $progressbar1 = GUICtrlCreateProgress(10, 20, 400, 20,$PBS_SMOOTH)
        $Progress1Text = GUICtrlCreateLabel("", 10, 44, 400, 20, $SS_LEFTNOWORDWRAP)
        $progressbar2 = GUICtrlCreateProgress(10, 60, 400, 20, $PBS_SMOOTH)
        $Progress2Text = GUICtrlCreateLabel("", 10, 82, 400, 20, $SS_LEFTNOWORDWRAP)
        GUISetFont(10, 600)
        GUISetState(@SW_SHOW)
        GUICtrlSetData($Progress1Text, "Working Directory " & $tosearch)
        $Run1 = 1
    EndIf
    
    $Size = DirGetSize($current, 3)
    $Qty = $Size[1]
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            $Qty -= 1
            $LocalPercent = 100 - (($Qty / $Size[1]) * 100)
            $OverallQty -= 1
            $overallpercent = 100 - (($OverallQty / $Overall[1]) * 100)
            GUICtrlSetData($Progress0Text, "Total Progress " & Int($overallpercent) & "% completed")
            GUICtrlSetData($progressbar1, $overallpercent)
            GUICtrlSetData($progressbar2, $LocalPercent)
            GUICtrlSetData($Progress2Text, "Copying File " & $file)
            
            If $useMultiColour then 
                GUICtrlSetColor($Progressbar2, _ChangeColour($LocalPercent))
                GUICtrlSetColor($Progressbar1, _ChangeColour($OverallPercent))
            EndIf
            
            $iRet = FileCopy($current & "\" & $file, $destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $overwrite + 8)
            If Not $iRet And (Not FileExists($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file) Or $overwrite) Then 
;               _rundos('robocopy "'& $current & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '" "' & $file & '" /np /zb /r:0 /w:0')
;ConsoleWrite('robocopy "'& $current & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '" "' & $file & '" /np /zb /r:0 /w:0' & @CRLF)
                _rundos('xcopy "'& $current & '\' & $file & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '" /g /h /r /y /z')
ConsoleWrite('xcopy "'& $current & '\' & $file & '" "' & $destination & StringTrimLeft($current, StringLen($source)) & '" /g /h /r /y /z' & @CRLF)
            EndIf
    
      FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            DirCreate($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file)
            FileSetAttrib($destination & StringTrimLeft($current, StringLen($source)) & "\" & $file, $attrib)
            GUICtrlSetData($Progress1Text, $current & "\" & $file)
            ProgressCopy($current & "\" & $file, $destination, $UseMultiColour, $attrib, $overwrite,1)
        EndIf
    WEnd
    FileClose($search)
    ;when overall percent = 100 set end gui text, delete gui and reset run1 to 0
    If $overallpercent = 100 Then
        GUICtrlSetData($Progress0Text, "Total Progress 100% completed")
        GUICtrlSetData($progressbar1, 100)
        GUICtrlSetData($progressbar2, 100)
        GUICtrlSetData($Progress2Text, "Done!")
        Sleep(2000)
        GUIDelete($PRCopyGui)
        $Run1 = 0
    EndIf
EndFunc  ;==>ProgressCopy

Right now is set to work with xcopy every Win NT plataform has xcopy, if you want to use robocopy don't forget that you will need to included robocopy.exe with your script using FileInstall().

Note:

xcopy you can not use /z and /o switches together is either one or the other one. I set the script with /z, don't know which one you need.

robocopy added switches /r:0 /w:0 otherwise if you have a corrupted file robocopy will try 1,000,000 times to copy that file and wait 30 seconds between tries.

Edit:

fix $overwrite switch for robocopy and xcopy.

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...