faustf Posted January 23, 2017 Posted January 23, 2017 hi guys i write a code , for sync two folder one in pc and other in siteweb , by protocol FTP , work all good , but not perfect , the problem is situated when i want cancel a file, if i select only one , work good , but if i do CTRL +A and select all , remove only one , someone can help me ??? thankx the code expandcollapse popup#include <APIConstants.au3> #include <GDIPlus.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <FTPEx.au3> #include <Misc.au3> #include <WinAPI.au3> #include <File.au3> #include "RDC.au3" Opt('MustDeclareVars', 1) Opt('TrayAutoPause', 0) Global $hWnd = GUICreate(''), $aDir[3], $iGResult, $sGPath_Monitor, $de = 0, $sGPath, $sGName_file, $sGpath_clean Local $sLRealPath = StringReplace(@ScriptDir, "\INCLUDE", "") $sGPath_Monitor = $sLRealPath & (IniRead(@ScriptDir & "\presync_conf.ini", "Path_to_sync", "key1", "Error")) Global $sGsplitPath = StringSplit(@ScriptDir, "\") Global $sGRealPath = $sGsplitPath[1] & "\" & $sGsplitPath[2] ; & "\" & $sGsplitPath[3] & "\" & $sGsplitPath[4] & "\" & $sGsplitPath[5] Global $sGServer = IniRead($sGRealPath & "\WEB-SITE\eBay\FTP\config_ftp.ini", "ftp_config", "server", "DEfault") Global $sGUser = IniRead($sGRealPath & "\WEB-SITE\eBay\FTP\config_ftp.ini", "ftp_config", "user", "DEfault") Global $sGPassw = IniRead($sGRealPath & "\WEB-SITE\eBay\FTP\config_ftp.ini", "ftp_config", "passw", "DEfault") Global $hDLL = DllOpen("user32.dll") Global $sGNameFold, $sGNameChange, $ChF = 0 _RDC_OpenDll() If @error Then ConsoleWrite('Error: _RDC_OpenDll() - ' & @error & @CR) MsgBox(16, 'Error !!!', 'Error: _RDC_OpenDll() - ' & @error & @CR) EndIf GUIRegisterMsg($WM_RDC, 'WM_RDC') _RDC_Create($sGPath_Monitor, 1, BitOR($FILE_NOTIFY_CHANGE_FILE_NAME, $FILE_NOTIFY_CHANGE_DIR_NAME, $FILE_NOTIFY_CHANGE_SIZE), 0, $hWnd) If @error Then ConsoleWrite('Error: _RDC_Create() - ' & @error & ', ' & @extended & @CR) MsgBox(16, 'Error !!!', 'Error: _RDC_Create() - ' & @error & ' ' & @extended & @CR) EndIf Func WM_RDC($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $aData = _RDC_GetData($lParam) If @error Then ConsoleWrite('Error: _RDC_GetData() - ' & @error & ', ' & @extended & ', ' & _RDC_GetDirectory($lParam) & @CR) MsgBox(16, 'Error !!!', 'Error: _RDC_GetData() - ' & @error & ' ' & @extended & ' ' & _RDC_GetDirectory($lParam) & @CR) _RDC_Delete($lParam) Return 0 EndIf For $i = 1 To $aData[0][0] $iGResult = $aData[$i][0] ; esito se 1 o 2 o 3 etc.. $de = 1 $sGpath_clean = _RDC_GetDirectory($lParam) $sGPath = ($aData[$i][1] & ' - ' & _RDC_GetDirectory($lParam) & $aData[$i][0] & @CR) $sGName_file = $aData[$i][1] Next Return 0 EndFunc ;==>WM_RDC Func _Elaborate_image($path_image) _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($path_image) If @error Then MsgBox(16, "Error", "Does the file exist?, is not File or Folder Please only File or Folder") Else If _GDIPlus_ImageGetWidth($hImage) > 500 Or _GDIPlus_ImageGetHeight($hImage) > 500 Then Local $iLNewHeight = (_GDIPlus_ImageGetHeight($hImage) / _GDIPlus_ImageGetWidth($hImage)) * 550 Local $iLNewWidth = (_GDIPlus_ImageGetWidth($hImage) / _GDIPlus_ImageGetHeight($hImage)) * $iLNewHeight EndIf Local $aLPath = StringSplit($path_image, "\") Local $sLNameFile = StringReplace($aLPath[$aLPath[0]], ".jpg", "") Local $sCLSID = _GDIPlus_EncodersGetCLSID("BMP") _GDIPlus_ImageSaveToFileEx($hImage, @TempDir & "\" & $sLNameFile & ".bmp", $sCLSID) _ImageResize(@TempDir & "\" & $sLNameFile & ".bmp", @TempDir & "\" & $sLNameFile & ".jpg", $iLNewWidth, $iLNewHeight) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() EndIf EndFunc ;==>_Elaborate_image Func _ImageResize($sInImage, $sOutImage, $iW, $iH) Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0 Local $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1)) Local $sOF = StringMid($sOutImage, StringInStr($sOutImage, "\", 0, -1) + 1) Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1)) $hWnd = _WinAPI_GetDesktopWindow() $hDC = _WinAPI_GetDC($hWnd) $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) _WinAPI_ReleaseDC($hWnd, $hDC) _GDIPlus_Startup() $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH) $CLSID = _GDIPlus_EncodersGetCLSID($Ext) $sOutImage = $sOP & $sOF _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID) _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose($hGraphic) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() EndFunc ;==>_ImageResize Func GetExplorerSelection() Local $saveClip = "" Local $filesFolders = "" Local $handle = _WinAPI_GetForegroundWindow() Local $className = _WinAPI_GetClassName($handle) If $className = "ExploreWClass" Or $className = "CabinetWClass" Then Send("^c") Sleep(50) ; give clipboard time to react $filesFolders = ClipGet() Return $filesFolders EndIf EndFunc ;==>GetExplorerSelection While 1 If $de = 1 Then Switch $iGResult Case $iGResult = 1 ; crea dir or file Sleep(5000) Local $a = 0 If StringInStr($sGName_file, ".") = 0 Then ; se non cè l'estensione vul dire che è una cartella allora fai Do $sGNameChange = GetExplorerSelection() $ChF = 1 Local $sNameMod4FTP = StringReplace($sGName_file, "\", "/") $sGNameFold = $sNameMod4FTP Local $Open = _FTP_Open('MyFTP Control') Local $Conn = _FTP_Connect($Open, $sGServer, $sGUser, $sGPassw) If @error Then MsgBox($MB_SYSTEMMODAL, '_FTP_Connect', 'ERROR=' & @error) Else If StringInStr($sGName_file, "\") = 0 Then ;MsgBox(0,'149',$sGName_file) Local $Ftpp = _FTP_DirCreate($Conn, '/public_html/sito2/eBay/FOTO/' & $sGName_file) $sGNameFold = $sGName_file Else ;MsgBox(0,'149',$sNameMod4FTP) Local $Ftpp = _FTP_DirCreate($Conn, '/public_html/sito2/eBay/FOTO/' & $sNameMod4FTP) EndIf EndIf Local $iFtpc = _FTP_Close($Conn) Local $iFtpo = _FTP_Close($Open) $a = 1 ;EndIf Until $a = 1 Else ; vuol dire che è un file Local $aLNameClean = StringSplit($sGName_file, "\") Local $aLALLFileinFolder = _FileListToArray($sGpath_clean & $aLNameClean[1], "*", 1) If @error = 1 Then MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.") EndIf If @error = 4 Then MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.") EndIf ; Display the results returned by _FileListToArray. ;_ArrayDisplay($aLALLFileinFolder) Local $sLNameClean = StringSplit($sGName_file, "\") Sleep(200) For $i = 1 To UBound($aLALLFileinFolder) - 1 If FileGetSize ($sGpath_clean & $aLNameClean[1] & "\" & $aLALLFileinFolder[$i]) > "1000000" Then Local $bLResult = _Elaborate_image($sGpath_clean & $aLNameClean[1] & "\" & $aLALLFileinFolder[$i]) FileCopy(@TempDir & "\" & $aLALLFileinFolder[$i], $sGpath_clean & $aLNameClean[1] & "\" & $aLALLFileinFolder[$i], $FC_OVERWRITE) EndIf Next Local $Open = _FTP_Open('MyFTP Control') Local $Conn = _FTP_Connect($Open, $sGServer, $sGUser, $sGPassw) If @error Then MsgBox($MB_SYSTEMMODAL, '_FTP_Connect', 'ERROR=' & @error) Else For $i = 1 To UBound($aLALLFileinFolder) - 1 Local $Ftpp = _FTP_FilePut($Conn, $sGpath_clean & $aLNameClean[1] & "\" & $aLALLFileinFolder[$i], '/public_html/sito2/eBay/FOTO/'& $aLNameClean[1] & "/" & $aLALLFileinFolder[$i] ) Next EndIf Local $iFtpc = _FTP_Close($Conn) Local $iFtpo = _FTP_Close($Open) EndIf $de = 0 Case $iGResult = 2 ; cancella file If StringInStr($sGName_file, ".") = 0 Then ; è una cartella Local $Open = _FTP_Open('MyFTP Control') Local $Conn = _FTP_Connect($Open, $sGServer, $sGUser, $sGPassw) If @error Then MsgBox($MB_SYSTEMMODAL, '_FTP_Connect', 'ERROR=' & @error) Else If StringInStr($sGName_file, "\") = 0 Then Local $Ftpp = _FTP_DirDelete($Conn, '/public_html/sito2/eBay/FOTO/' & $sGName_file) Else Local $sNameMod4FTP = StringReplace($sGName_file, "\", "/") Local $Ftpp = _FTP_DirDelete($Conn, '/public_html/sito2/eBay/FOTO/' & $sNameMod4FTP) EndIf EndIf Local $iFtpc = _FTP_Close($Conn) Local $iFtpo = _FTP_Close($Open) Else ; é un file _ArrayDisplay($aData,'216') MsgBox(0,'',$sGName_file) Local $Open = _FTP_Open('MyFTP Control') Local $Conn = _FTP_Connect($Open, $sGServer, $sGUser, $sGPassw) If @error Then MsgBox($MB_SYSTEMMODAL, '_FTP_Connect', 'ERROR=' & @error) Else If StringInStr($sGName_file, "\") = 0 Then Local $Ftpp = _FTP_FileDelete($Conn, '/public_html/sito2/eBay/FOTO/' & $sGName_file) Else Local $sNameMod4FTP = StringReplace($sGName_file, "\", "/") Local $Ftpp = _FTP_FileDelete($Conn, '/public_html/sito2/eBay/FOTO/' & $sNameMod4FTP) EndIf EndIf Local $iFtpc = _FTP_Close($Conn) Local $iFtpo = _FTP_Close($Open) EndIf $de = 0 Case $iGResult = 3 ; modifica file MsgBox(0, '', 'modifico il file ') $de = 0 Case $iGResult = 4 ; nome vecchio MsgBox(0, 'nome vecchio', $sGName_file) $de = 0 Case $iGResult = 5 ; nome nuovo Local $sLNomenew = GetExplorerSelection() Local $aLNameSplit = StringSplit($sLNomenew, "\") $sLNomenew = $aLNameSplit[($aLNameSplit[0] - 1)] & "/" & $aLNameSplit[$aLNameSplit[0]] If StringInStr($sGName_file, ".") = 0 Then ;cartella Local $Open = _FTP_Open('MyFTP Control') Local $Conn = _FTP_Connect($Open, $sGServer, $sGUser, $sGPassw) If @error Then MsgBox($MB_SYSTEMMODAL, '_FTP_Connect', 'ERROR=' & @error) Else Local $sNameMod4FTP = StringReplace($sGName_file, "\", "/") Local $Ftpp = _FTP_Command($Conn, "RNFR /public_html/sito2/eBay/FOTO/" & $sLNomenew) Local $Ftpp = _FTP_Command($Conn, "RNTO /public_html/sito2/eBay/FOTO/" & $sNameMod4FTP) EndIf Local $iFtpc = _FTP_Close($Conn) Local $iFtpo = _FTP_Close($Open) Else Local $Open = _FTP_Open('MyFTP Control') Local $Conn = _FTP_Connect($Open, $sGServer, $sGUser, $sGPassw) If @error Then MsgBox($MB_SYSTEMMODAL, '_FTP_Connect', 'ERROR=' & @error) Else Local $sNameMod4FTP = StringReplace($sGName_file, "\", "/") _FTP_FileRename($Conn, "/public_html/sito2/eBay/FOTO/" & $sLNomenew, "/public_html/sito2/eBay/FOTO/" & $sNameMod4FTP) EndIf Local $iFtpc = _FTP_Close($Conn) Local $iFtpo = _FTP_Close($Open) ;file EndIf $de = 0 EndSwitch EndIf WEnd i used this UDF thankz again at all
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