const service_ftp=1
const open_type_direct=1
const ftp_transfer_type_ascii=1
Const GENERIC_READ = &H80000000
'Extern is a QuickTest object to declare an external functions
Extern.Declare miclong, "InternetOpen", "wininet.dll", "InternetOpenA",_ micString, micDWord, micString, micString, micDWordExtern.Declare miclong, "InternetConnect", "wininet.dll", "InternetConnectA",_ micLong, micString, micInteger, micString, micString, micDWord, micDWord,_ micDWord
Extern.Declare miclong, "FtpOpenFile", "wininet.dll", "FtpOpenFileA", micLong,_ micString, micDWord, micDWord, micDWord
Extern.Declare micinteger, "InternetCloseHandle", "wininet.dll",_
"InternetCloseHandle", miclong
hnd_internet=Extern.InternetOpen("QTP_FTP", open_type_direct, vbnullchar,vbnullchar,0)
if hnd_internet=0 then
msgbox "Connection is Failed - 1"
Else
msgbox "Connection is Successful - 1"
End If
hnd_connection=Extern.InternetConnect(hnd_internet, "ftp.microsoft.com", 21,"","",1,0,0)
If hnd_connection=0 then
msgbox "Connection is Failed - 2"
Else
msgbox "Connection is Successful - 2"
End If
a=Extern.FtpOpenFile(hnd_connection,"/MISC/INDEX.TXT",GENERIC_READ,1,0)
msgbox a
Extern.InternetCloseHandle(hnd_connection)
Extern.InternetCloseHandle(hnd_internet)
ftpopenfile opens access to a remote file on an FTP server for reading or writing. first parameter is the handle to the FTP connection. Second parameter is the name of the file to open. third parameter is File access. This parameter can be GENERIC_READ or GENERIC_WRITE, but not both. We are using it for reading. Next parameter is how file downloading will be handled in our case we have used - "ftp_transfer_type_ascii=1" and the last parameter is used if we are using callbacks. As we are not using callbacks so it is kept at 0.
ftpopenfile returns a handle if successful, or NULL otherwise
Also See:
QTP FTP Main Post
FTP InternetOpen
FTP InternetConnect
FTPGetFile
FTPPutFile
FTPSetCurrentDirectory
FTPCreateDirectory
FTPRenameFile
FTPRemoveDirectory
FTPDeleteFile