1/13powerbuilder利用wininet,实现FTP上传与下载第一,定义一个结构体globaltypest_filetimefromstructureunsignedlongdwLowDateTimeunsignedlongdwHighDateTimeendtype---------------------------------------------------第二,还是定义一个结构体globaltypest_win32finddatafromstructureunsignedlongdwFileAttributesst_filetimeftCreationTimest_filetimeftLastAccessTimest_filetimeftLastWriteTimeunsignedlongnFileSizeHighunsignedlongnFileSizeLowunsignedlongdwReserved0unsignedlongdwReserved1charactercFileName[256]charactercAlternateFileNameendtype------------------------------------------------------第三,定义一个FTP对象forwardglobaltypeue_ftpfromnonvisualobjectendtypeendforwardsharedvariablesendvariablesglobaltypeue_ftpfromnonvisualobjectendtypeglobalue_ftpue_ftptypeprototypes//检查连接FUNCTIONLongInternetCheckConnection(StringlpszUrl,LongdwFlags,LongdwReserved)LIBRARYwininet.dllALIASFORInternetCheckConnectionA2/13//激活连接FUNCTIONLongInternetAttemptConnect(LongdwReserved)LIBRARYwininet.dll//初始化一个连FUNCTIONLongInternetOpen(StringlpszAgent,LongdwAccessType,StringlpszProxy,StringlpszProxyBypass,LongdwFlags)LIBRARYwininet.dllALIASFORInternetOpenA//连接服务器FUNCTIONLongInternetConnect(LonghInternet,StringlpszServerName,longnServerPort,StringlpszUserName,StringlpszPassword,LongdwService,LongdwFlags,REFLongdwContext)LIBRARYWinInet.dllALIASFORInternetConnectA//打开一个URlFUNCTIONLongInternetOpenUrl(LonghInternet,StringlpszUrl,StringlpszHeaders,LongdwHeadersLength,LongdwFlags,REFLongdwContext)LIBRARYwininet.dllALIASFORInternetOpenUrlA//断开连接FUNCTIONLongInternetCloseHandle(LonghInternet)LIBRARYwininet.dll//向FTP服务器发送指令FUNCTIONBooleanFtpCommand(LonghConnect,BooleanlfExpectResponse,LongdwFlags,refStringlpszCommand,LongdwContext,refLongphFtpCommand)LIBRARYWinInet.dllALIASFORFtpCommandA////////////////////////////////////////////文件操作函数//FileOperatorFunction///////////////////////////////////////////下载文件--DownloadFileFUNCTIONBooleanFtpGetFile(LonghConnect,StringlpszRemoteFile,StringlpszNewFile,BooleanfFailIfExists,LongdwFlagsAndAttributes,LongdwFlags,REFLongdwContext)LIBRARYWinInet.dllALIASFORFtpGetFileA//上传文件--UploadfileFUNCTIONBooleanFtpPutFile(LonghConnect,StringlpszLocalFile,StringlpszNewRemoteFile,LongdwFlags,LongdwContext)LIBRARYWinInet.dllALIASFORFtpPutFileA//删除文件--DeletefileFUNCTIONBooleanFtpDeleteFile(LonghConnect,StringlpszFileName)LIBRARYWinInet.dllALIASFORFtpDeleteFileA//打开文件--OpenfileFUNCTIONLongFtpOpenFile(LonghConnect,refStringlpszFileName,LongdwAccess,LongdwFlags,refLongdwContext)LIBRARYWinInet.dllALIASFORFtpOpenFileA//取得文件大小--GetfilesizeFUNCTIONLongFtpGetFileSize(LonghFile,refLonglFileSizeHigh)LIBRARYWinInet.dllALIASFORFtpGetFileSizeA//读取文件--ReadfileFUNCTIONBooleanInternetReadFile(LonghFile,refstringlpBuffer,LongdwNumberOfBytesToRead,REFLonglpdwNumberOfBytesRead)LIBRARYwininet.dll//////////////////////////////////////////3/13//FTP目录操作函数//DirectoryOperatorFunction////////////////////////////////////////////取得当前目录FUNCTIONBooleanFtpGetCurrentDirectory(LonghConnect,REFStringlpszCurrentDirectory,REFLonglpdwCurrentDirectory)LIBRARYWinInet.dllALIASFORFtpGetCurrentDirectoryA//创建一个目录FUNCTIONBooleanFtpCreateDirectory(LonghConnect,refStringlDirectory)LIBRARYWinInet.dllALIASFORFtpCreateDirectoryA//文件的信息或者指定文件夹下面第一个文件/文件夹的信息。FUNCTIONLongFtpFindFirstFile(LonghConnect,refStringlpszSearchFile,refst_win32finddatalpFindFileData,longdwFlags,refLongdwContext)LIBRARYWinInet.dllALIASFORFtpFindFirstFileA//取得目录下一个文件/文件夹的信息FUNCTIONBooleanInternetFindNextFile(LonghFirstName,refst_win32finddatalpFindFileData)LIBRARYwininet.dllALIASFORInternetFindNextFileA//改变当前目录FUNCTIOnBOOLEANFtpSetCurrentDirectory(LonghConnect,refStringlDirectory)LIBRARYWinInet.dllALIASFORFtpSetCurrentDirectoryA////////////////////////////////////////////本地目录操作函数//DirectoryOperatorFunction////////////////////////////////////////////取得本地目录下一个文件/文件夹的信息FUNCTIONLongFindFirstFile(stringsFirstName,refst_win32finddatalpFindFileData)LIBRARYKernel32.dllALIASFORFindFirstFileAFUNCTIONbooleanFindNextFile(longsFirstName,refst_win32finddatalpFindFileData)LIBRARYKernel32.dllALIASFORFindNextFileAFUNCTIONbooleanFindClose(longsFirstName)LIBRARYKernel32.dllALIASFORFindCloseAendprototypestypevariables//初始化返回值Longii_Seesion//连接服务器返回值Longii_ServerSeesion//当前目录Stringis_CurrDirectory//ftpserver上的指定的文件的信息或者指定文件下面第一个文件/文件夹的信息st_win32finddatait_finddata//当前打开文件返回值longii_FileSeesion//文件属性值4/13CONSTANTLongFILE_ATTRIBUTE_NORMAL=0CONSTANTLongFILE_ATTRIBUTE_READONLY=1CONSTANTLongFILE_ATTRIBUTE_HIDDEN=2CONSTANTLongFILE_ATTRIBUTE_SYSTEM=4CONSTANTLongFILE_ATTRIBUTE_VOLUME=8CONSTANTLongFILE_ATTRIBUTE_DIRECTORY=16CONSTANTLongFILE_ATTRIBUTE_ARCHIVE=32CONSTANTLongFILE_ATTRIBUTE_ALIAS=64CONSTANTLongFILE_ATTRIBUTE_COMPRESSED=128CONSTANTLongINTERNET_MAX_PATH_LENGTH=2048CONSTANTLongGENERIC_READ=2147483648CONSTANTLongGENERIC_Write=1073741824CONSTANTLongGENERIC_RW=3221225472//Internet连接标识CONSTANTLongCONNECTION_MODEM=1CONSTANTLongCONNECTION_LAN=2CONSTANTLongCONNECTION_PROXY=4CONSTANTLongCONNECTION_MODEM_BUSY=8CONSTANTLongINTERNET_FLAG_ASYNC=268435456CONSTANTLongINTERNET_FLAG_SECURE=8388