;FTP stuff ;adjusted for increased usability ;-globals Global hInternetConnect.l Global hInternetSession.l ;-Constants #MCM_GETCURSEL = $1001 #DTM_SETSYSTEMTIME = $1002 #MAX_PATH = 260 #FILE_ATTRIBUTE_READONLY = 1 #FILE_ATTRIBUTE_HIDDEN = 2 #FILE_ATTRIBUTE_SYSTEM = 4 #FILE_ATTRIBUTE_DIRECTORY = 16 #FILE_ATTRIBUTE_ARCHIVE = 32 #FILE_ATTRIBUTE_NORMAL = 128 #FILE_ATTRIBUTE_TEMPORARY = 256 #FILE_ATTRIBUTE_COMPRESSED = 2048 #NO_ERROR = 0 #ERROR_NO_MORE_FILES = 18 #ERROR_INTERNET_EXTENDED_ERROR = 12003 #FTP_TRANSFER_TYPE_BINARY = 2 #INTERNET_OPEN_TYPE_DIRECT = 1 #INTERNET_DEFAULT_FTP_PORT = 21 #INTERNET_SERVICE_FTP = 1 #INTERNET_SERVICE_PASSIVE = $8000000 ;expressed in hex: 134217728 as decimal Procedure.s CurrentTime() ;from paul GetLocalTime_(time.SYSTEMTIME) hour$=Str(time\wHour) minute$=Str(time\wMinute) second$=Str(time\wSecond) If Len(hour$)=1:hour$="0"+hour$:EndIf If Len(minute$)=1:minute$="0"+minute$:EndIf If Len(second$)=1:second$="0"+second$:EndIf curtime$=hour$+":"+minute$+":"+second$ ProcedureReturn curtime$ EndProcedure Procedure ShowErrors(n.l) ;actually tryies to clear all errors msg.s="" While n Select n Case #ERROR_PATH_NOT_FOUND msg="Path not found" Case #ERROR_ACCESS_DENIED msg="Access restricted" Case #ERROR_INVALID_ACCESS msg="Access invalid" Case #ERROR_INVALID_HANDLE msg="Invalid handle" Case #ERROR_NO_MORE_FILES msg="No more files" Case #ERROR_INTERNET_EXTENDED_ERROR msg="exteded error" Case #ERROR_FILE_NOT_FOUND msg="File not found" Case #ERROR_NETWORK_ACCESS_DENIED msg="Network access denied" Case #ERROR_FILE_EXISTS msg="File Exits" Case #ERROR_ALREADY_ASSIGNED msg="Device name already in use" Case #ERROR_INVALID_PASSWORD msg="Invalid password" Case #ERROR_INVALID_PARAMETER msg="Invalid paremeter" Case #ERROR_RESOURCE_TYPE_NOT_FOUND msg="Invalid resource specified" Default msg="unknown error" EndSelect MessageRequester("FTP Some Error","Error#="+Str(n)+msg,0) n=GetLastError_() Wend EndProcedure Procedure FTPDisconnect() If hInternetSession If hInternetConnect InternetCloseHandle_(hInternetConnect) hInternetConnect = #False EndIf InternetCloseHandle_(hInternetSession) hInternetSession = #False EndIf ; -------------------------------------------------------------------------- ; Hangup the modem if the program created the connection automatically. ; -------------------------------------------------------------------------- If InternetAutodialHangup_(0) MessageRequester("FTP Status","Disconnected",0) Else MessageRequester("Failure warning!","You will have to disconnect your internet connection manually!"+Chr(10)+Chr(10)+"Sorry, my automated attempt has failed...",0) EndIf EndProcedure Procedure FTPConnect(Site.s,UN.s,PW.s) ;attempts to connect to a FTP site Static PassWord.s Static UserName.s Static FTPSite.s If hInternetConnect If FTPSite<>Site FTPDisconnect() PassWord=PW UserName=UN FTPSite=Site EndIf ;MessageRequester("FTP Error","Already connected, you must disconnect first",0) Else PassWord=PW UserName=UN FTPSite=Site EndIf If hInternetConnect=0 hInternetSession = InternetOpen_("FTP", #INTERNET_OPEN_TYPE_DIRECT, "", "", 0) If hInternetSession hInternetConnect = InternetConnect_(hInternetSession, @FTPSite, #INTERNET_DEFAULT_FTP_PORT, @UserName, @Password, #INTERNET_SERVICE_FTP, 0, 0) If hInternetConnect MessageRequester("Norm's FTP","Connection Achieved",0) Else MessageRequester("FTP Error","Unable to connect to "+FTPSite,0) EndIf Else MessageRequester("FTP Error","Unable to access the internet",0) hInternetConnect=0 EndIf EndIf EndProcedure Procedure.l ChangeFTPDir(NewPath.s) reply.l=0 Static OldPath.s If NewPath<>OldPath If hInternetConnect If FtpSetCurrentDirectory_(hInternetConnect, NewPath) reply=1 Else MessageRequester("FTP Error","Unable to change FTP dir to "+NewPath,#MB_ICONSTOP) ShowErrors(GetLastError_()) FtpSetCurrentDirectory_(hInternetConnect,"..") ShowErrors(GetLastError_()) ;*p\FTPUploadDir=Space(250) path.s=Space(250) ml.l=250 ml=FtpGetCurrentDirectory_(hInternetConnect,@path,@ml) ShowErrors(GetLastError_()) OldPath=path MessageRequester("FTP Status","Switched to path="+OldPath,0) EndIf Else MessageRequester("FTP Error","Not connected to FTP Site",#MB_ICONSTOP) EndIf EndIf EndProcedure Procedure GetFileFTP(FTPName.s,LName.s) error.l=0 If FtpGetFile_(hInternetConnect, FTPName, LName, 0, #FILE_ATTRIBUTE_NORMAL, #FTP_TRANSFER_TYPE_BINARY,0) MessageRequester("FTP Status","Downloaded file "+LName+" - "+Str(FileSize(LName))+"Bytes",0) Else ; Drat! That failed, so try to delete it in the archive directory and try again. MessageRequester("FTP Error","Can't receive this file: "+LName + " " + Str(GetLastError_()),0) error = 1 ; Set the failure flag EndIf ProcedureReturn error EndProcedure Procedure.l PutFileFTP(LName.s,FTPName.s) error.l=0 If FtpPutFile_(hInternetConnect, LName, FTPName, 0, 0) MessageRequester("FTP Status","Uploaded "+LName+" - "+Str(FileSize(LName))+" Bytes",0) Else ; Oops! The file send failed... report it with the error code. MessageRequester("FTP Error","Can't send this file: "+LName+ Str(GetLastError_()),0) error = 1 EndIf ProcedureReturn error EndProcedure ;this procedure replaced byt the PB call .... ;result.l=GetFileDate(FN$,Flag.l) where flag = ;#PB_Date_Created ;#PB_Date_Accessed ;#PB_Date_Modified ;Procedure.l GetFileDate(FN.s) ; Ftime.l=0 ; lpCreationTime.FILETIME ; lpLastAccessTime.FILETIME ; lpLastWriteTime.FILETIME ; ; ;lpFileInformation.PB_FIND_DATA ; ;lpLastWriteTime2.l=0 ; *lpReOpenBuff=AllocateMemory(1000) ; *lpDL=AllocateMemory(100) ; hFile.l=OpenFile_(FN, *lpReOpenBuff, #FILE_ATTRIBUTE_READONLY) ; time.SYSTEMTIME ; ; If hFile ; ; GetFileTime_(hFile, @lpCreationTime, @lpLastAccessTime, @lpLastWriteTime) ; CancelIo_(hFile) ; ; FileTimeToSystemTime_(@lpCreationTime,@time) ; ; Ftime=Date(time\wyear,time\wmonth,time\wday,0,0,0) ; Else ; MessageRequester("FTP Error GetDate","Unable to locate file name "+FN,#MB_ICONSTOP) ; EndIf ; ; ProcedureReturn FTime ;EndProcedure Procedure.l GetFTPFileDate(FN.s) FD.WIN32_FIND_DATA If hInternetConnect LShFindFile = FtpFindFirstFile_(hInternetConnect, FN, @FD, 0, 0) If LShFindFile=0 MessageRequester("FTP Error FTPGetDate","Unable to locate file "+FN,#MB_ICONSTOP) Else InternetCloseHandle_(LShFindFile) EndIf EndIf lpLocalFileTime.FILETIME FileTimeToLocalFileTime_(@FD\ftCreationTime, @lpLocalFileTime) time.SYSTEMTIME FileTimeToSystemTime_(@lpLocalFileTime,@time) Ftime=Date(time\wyear,time\wmonth,time\wday,0,0,0) ProcedureReturn Ftime EndProcedure ; IDE Options = PureBasic v4.02 (Windows - x86) ; CursorPosition = 249 ; FirstLine = 214 ; Folding = --