#NoTrayIcon #include #include #include #include #include #include #include GUISetState(@SW_HIDE, "FTP_VPDK") ;Mã lấy tên thư mục theo ngày tháng hiện tại máy chủ Local $sJulDate = _DateToDayValue(@YEAR, @MON, @MDAY) Local $Y, $M, $D $sJulDate = _DayValueToDate($sJulDate, $Y, $M, $D) $NAM_THANG_NGAY = $Y&$M&$D ;Đọc thông số kết nối từ file TXT FileOpen("Confilg_FTP.txt",0) $Ftp_host = FileReadLine("Confilg_FTP.txt", 1) ;Thông số kết nối máy chủ FTP $server = FileReadLine("Confilg_FTP.txt", 1) ;Địa chỉ HOST $username = FileReadLine("Confilg_FTP.txt", 2) ;Tên đăng nhập $pass = FileReadLine("Confilg_FTP.txt", 3) ;Mật khẩu $dllhandle = DllOpen('wininet.dll') ; Đường dẫn thư mục trên máy tính điểm đổi GPLX $DATA_GPLX = FileReadLine("Confilg_FTP.txt", 4)&$NAM_THANG_NGAY&'\' ;Đường dẫn thư mục ảnh gốc cần tải lên $DIR_GPLX = FileReadLine("Confilg_FTP.txt", 4)&$NAM_THANG_NGAY ;Đường dẫn thư mục rỗng chưa có file ;Đường dẫn trên FTP SERVER Sở GTVT Đồng Nai $DATA_FTP = FileReadLine("Confilg_FTP.txt", 5) $FTP_NAME = FileReadLine("Confilg_FTP.txt", 6) ;Số lần lặp lại bước tải file, Thời gian lặp, loại file, Dung lượng tối thiểu, tối đa $Lap = FileReadLine("Confilg_FTP.txt", 7) $TIME_LAP = FileReadLine("Confilg_FTP.txt", 8) $FILE_SYS = FileReadLine("Confilg_FTP.txt", 9) $Min_file = FileReadLine("Confilg_FTP.txt", 10) $Max_file = FileReadLine("Confilg_FTP.txt", 11) FileClose("Confilg_FTP.txt") While $Lap > 0 ;lặp đến khi nào < 0 thì dừng ;Thời gian lặp 300.000 = 5 phút sleep($TIME_LAP) $Open = _FTP_Open($FTP_NAME) $Conn = _FTPConnect($Open, $server, $username, $pass,0,1,0x08000000) ;Tạo một thư mục có tên theo ngày tháng năm trên máy chủ FTP nếu nó tồn tại $KT = direxists2($DATA_GPLX) If $KT = 1 Then _FTP_DirCreate($Conn,$DATA_FTP&$NAM_THANG_NGAY) ;Tìm tất cả file ảnh trên thư mục lưu của máy chủ Local $aFileList = _FileListToArray($DATA_GPLX, $FILE_SYS) $iMax = UBound($aFileList) For $i = 1 to $iMax - 1; Vòng lặp thực hiện tải số file tìm được lên máy chủ Sở GTVT $File_name = $aFileList[$i] Local $iFileSize = ByteSuffix(FileGetSize($DATA_GPLX&$File_name)) If $iFileSize >= $Min_file and $iFileSize <= $Max_file Then $Ftpp = _FtpPutFile($Conn,$DATA_GPLX&$File_name, $DATA_FTP&$NAM_THANG_NGAY&'/'&$File_name , 0x08000000) EndIf Next $Lap = $Lap - 1 EndIf Local $iFtpc = _FTP_Close($Open) WEnd ;Hàm xử lý kết nối FTP máy con và máy chủ Func _FTPConnect($l_InternetSession, $s_ServerName, $s_Username, $s_Password, $i_ServerPort = 0, $l_Service = 1, $l_Flags = 0, $l_Context = 0) Local $ai_InternetConnect = DllCall('wininet.dll', 'long', 'InternetConnect', 'long', $l_InternetSession, 'str', $s_ServerName, 'int', $i_ServerPort, 'str', $s_Username, 'str', $s_Password, 'long', $l_Service, 'long', $l_Flags, 'long', $l_Context) If @error OR $ai_InternetConnect[0] = 0 Then SetError(-1) Return 0 EndIf Return $ai_InternetConnect[0] EndFunc Func _FtpPutFile($l_FTPSession, $s_LocalFile, $s_RemoteFile, $l_Flags = 0, $l_Context = 0) Local $ai_FTPPutFile = DllCall('wininet.dll', 'int', 'FtpPutFile', 'long', $l_FTPSession, 'str', $s_LocalFile, 'str', $s_RemoteFile, 'long', $l_Flags, 'long', $l_Context) If @error OR $ai_FTPPutFile[0] = 0 Then SetError(-1) Return 0 EndIf Return $ai_FTPPutFile[0] EndFunc ;Hàm tính dung lượng của file trước khi tải lên Func ByteSuffix($iBytes) Local $iIndex = 0 While $iBytes > 1023 $iIndex += 1 $iBytes /= 1024 WEnd Return Round($iBytes) EndFunc ;==>ByteSuffix ;Hàm kiểm tra sự tồn tại của thư mục trên máy con Func direxists2($dir) $err = _RunDOS("dir " & $dir) If $err = 0 Then Return 1 Else SetError(1) Return 0 EndIf EndFunc ;==>direxists2