tenrev Posted August 23, 2013 Share Posted August 23, 2013 Hi everyone, I just want to ask help.. I just want to make an autoit program that will download all the file (folders with files and sub folders and files) im able to do the basic things.. open, connect, get,close.. what i cant do is download files and folders in one code. what i really want to do is doing a backup.. - at first, download all files from the ftp and compress it with file name of date&time - then next back up would be all the new and modified files (in there respective dir) will be downloaded from ftp then compress it with filename of date&time -backup will be done just once a week.. hope you can help me.. Link to comment Share on other sites More sharing options...
orbs Posted August 23, 2013 Share Posted August 23, 2013 assuming there is no application already capable of doing it, it seems that recursion of the FTP folders is in order here, so for each FTP file you can compare to local file, so you can determine which file is to be downloaded. you cannot download only changes with one FTP command. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
EKY32 Posted August 23, 2013 Share Posted August 23, 2013 WELL, "orbs" gave you the main part of the answer but you can still create a small backup script which needs some hard working using_FTP_FindFileFirst , _FTP_FindFileNext , or _FTP_ListToArray to identify the files and download them in the order they are on the server. [font="'trebuchet ms', helvetica, sans-serif;"]Please mark the answer of your question if you found it.[/font] Link to comment Share on other sites More sharing options...
michaelslamet Posted August 23, 2013 Share Posted August 23, 2013 Download whole file from FTP server just to make a comparation with local file is not a good idea. You should maintaince a text file in the FTP server contain full path+filename and the file checksum, something like this: c:myfoldermyfile1.exe=0x75A76530D5FCB63064ADFC5262D5B5B5 c:myfoldermyfile2.exe=0xF4F5F49CC99CFD355F51849036D84D81 So instead of download the full file, you can download just the text file and compare the file checksum against the local file. To generate the checksum, you can many methods, this is the code for MD5 and CRC32: ; By guinness - 2012-2013. Func _MD5Hash($sFilePath, $iPercentageRead = Default) ; Default is 100 percent. $iPercentageRead = Int($iPercentageRead) If ($iPercentageRead > 100) Or ($iPercentageRead < 0) Then $iPercentageRead = 100 EndIf Return _Crypt_HashData(FileRead($sFilePath, ($iPercentageRead / 100) * FileGetSize($sFilePath)), $CALG_MD5) EndFunc ;==>_MD5Hash expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name ..........: _CRC32ForFile ; Description ...: Calculates CRC32 value for the specific file. ; Syntax ........: _CRC32ForFile($sFilePath) ; Parameters ....: $sFilePath - Full path to the file to process. ; $iPercentageRead - [optional] Percentage of file to read. Default is 100. ; Return values .: Success - Returns CRC32 value in the form of a hex string ; - Sets @error to 0 ; Failure - Returns empty string and sets @error: ; |1 - CreateFile function or call to it failed. ; |2 - CreateFileMapping function or call to it failed. ; |3 - MapViewOfFile function or call to it failed. ; |4 - RtlComputeCrc32 function or call to it failed. ; Author ........: trancexx ; Modified ......: guinness ; Link ..........: http://www.autoitscript.com/forum/topic/95558-crc32-md4-md5-sha1-for-files/ ; Example .......: No ; =============================================================================================================================== Func _CRC32ForFile($sFilePath, $iPercentageRead = 100) $iPercentageRead = Int($iPercentageRead) If ($iPercentageRead > 100) Or ($iPercentageRead < 0) Then $iPercentageRead = 100 EndIf $iPercentageRead = ($iPercentageRead / 100) * FileGetSize($sFilePath) Local $iError = 0 Local Const $hFilePath = _WinAPI_CreateFileEx($sFilePath, $OPEN_EXISTING, $GENERIC_READ, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $SECURITY_ANONYMOUS, 0, 0) If @error Then Return SetError(1, 0, '') EndIf Local Const $hFilePathMappingObject = _WinAPI_CreateFileMapping($hFilePath, 0, 0, $PAGE_READONLY) $iError = @error _WinAPI_CloseHandle($hFilePath) If $iError Then Return SetError(2, 0, '') EndIf Local Const $pFilePath = _WinAPI_MapViewOfFile($hFilePathMappingObject, 0, $iPercentageRead, $FILE_MAP_READ) $iError = @error _WinAPI_CloseHandle($hFilePathMappingObject) If $iError Then Return SetError(3, 0, '') EndIf Local Const $iBufferSize = $iPercentageRead ; FileGetSize($sFilePath) Local Const $iCRC32 = _WinAPI_ComputeCrc32($pFilePath, $iBufferSize) $iError = @error _WinAPI_UnmapViewOfFile($pFilePath) _WinAPI_CloseHandle($hFilePathMappingObject) If $iError Then Return SetError(4, 0, '') EndIf Return SetError(0, 0, Hex($iCRC32, 8)) EndFunc ;==>_CRC32ForFile Thanks to guiness and trancexx for this code Link to comment Share on other sites More sharing options...
orbs Posted August 23, 2013 Share Posted August 23, 2013 and how, pray tell, will this text file be updated with the new checksum when one of the FTP files is modified? comparison does not need to be by contents; i'd use time stamp or size, which can be compared without downloading the file. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
michaelslamet Posted August 23, 2013 Share Posted August 23, 2013 Whatever applications that change those FTP files have to maintain the text file If cant do it that way, dont use this method. Time stamp or size is another way, but it doesn't bullet proof. If we want to be sure that the file is same/different, we should use file checksum, IMHO. EKY32 1 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