标签:
Public Function Func_FTP(Operation,ServerName,UserName,Password,RemoteLocation,LocalLocation) ‘Set up the environment Const INTERNET_OPEN_TYPE_DIRECT = 1 Extern.Declare micLong, "InternetOpen", "wininet.dll", "InternetOpenA", micString, micDWord, micString, micString, micDWord Dim hInternet hInternet = Extern.InternetOpen( "QTP_FTP", INTERNET_OPEN_TYPE_DIRECT, vbNullChar, vbNullChar, 0 ) If hInternet = 0 Then Func_FTP= False Reporter.ReportEvent micFail, "InternetOpen", "Failed to setup environment." Exit Function end If ‘ Open ftp server Extern.Declare micLong, "InternetConnect", "wininet.dll", "InternetConnectA", micLong, micString, micInteger, micString, micString, micDWord, micDWord, micDWord Const INTERNET_DEFAULT_FTP_PORT = 22 Const INTERNET_SERVICE_FTP = 1 Dim hConnect hConnect = Extern.InternetConnect(hInternet,ServerName,INTERNET_DEFAULT_FTP_PORT,UserName,Password,INTERNET_SERVICE_FTP,0, 0 ) If hConnect = 0 Then Func_FTP= False Reporter.ReportEvent micFail, "InternetConnect", "Failed to open internet connection." Exit Function end If Dim bRetval Select case lcase(Operation) Case "getfile" ‘Get file Extern.Declare micInteger, "FtpGetFile", "wininet.dll", "FtpGetFileA", micLong, micString, micString, micInteger, micDWord, micDWord, micDWord Const FTP_TRANSFER_TYPE_ASCII = 1 bRetval = Extern.FtpGetFile( hConnect, RemoteLocation, LocalLocation, False, 0, FTP_TRANSFER_TYPE_ASCII, 0 ) wait(2) If Not CBool( bRetVal ) Then Func_FTP= False Reporter.ReportEvent micFail, "FtpGetFile " & RemoteLocation, "Failed to download file. at " & LocalLocation Exit Function end If Case "putfile" ‘put file Extern.Declare micInteger, "FtpPutFile", "wininet.dll", "FtpPutFileA", micLong, micString, micString, micDWord bRetval = Extern.FtpPutFile( hConnect,LocalLocation,RemoteLocation, 0 ) wait(2) If Not CBool( bRetVal ) Then Reporter.ReportEvent micFail, "FtpPutFile " & LocalLocation , "Failed to upload file. at " & RemoteLocation Func_FTP= False Exit Function End If Case "deletefile" ‘delete file Extern.Declare micInteger, "FtpDeleteFile", "wininet.dll", "FtpDeleteFileA",micLong,micstring bRetval =Extern.FtpDeleteFile(hConnect,RemoteLocation) wait(2) If Not CBool( bRetVal ) Then Reporter.ReportEvent micFail, "FtpPutFile", "Failed to delete file.--" & RemoteLocation Func_FTP= False Exit Function End If Case "findfile" Dim WIN32_FIND_DATA Extern.Declare micInteger, "FtpFindFirstFile", "wininet.dll", "FtpFindFirstFileA", micLong, micString,miclong, micDWord bRetval =Extern.FtpFindFirstFile(hConnect,RemoteLocation,WIN32_FIND_DATA,INTERNET_FLAG_NO_CACHE_WRITE) bRetval=left(bRetval,2) If bRetVal=0 Then Func_FTP= False Reporter.ReportEvent micFail, "File Not Found ", "File Not found ." Exit Function End If Case else End Select ‘Close Connections Extern.Declare micInteger, "InternetCloseHandle", "wininet.dll","InternetCloseHandle", micLong Extern.InternetCloseHandle( hConnect ) Extern.InternetCloseHandle( hInternet ) End Function
But wininet.dll does‘t support sFTP
FTP- Download, upload, Delete & find files
标签:
原文地址:http://www.cnblogs.com/ellie-test/p/4683062.html