QTP Script to download file from Unix Box or RDP to local machine

Set pop = CreateObject("wscript.shell")

Const DEFAULT_FTP_PORT=21
Const SERVICE_FTP=1
Const OPEN_TYPE_DIRECT=1
Const FTP_TRANSFER_TYPE_ASCII=1

Extern.Declare micLong, "InternetOpen", "wininet.dll", "InternetOpenA", micString, micDWord, micString, micString, micDWord
Extern.Declare micLong, "InternetConnect", "wininet.dll", "InternetConnectA", micLong, micString, micInteger, micString, micString, micDWord, micDWord, micDWord
Extern.Declare micInteger,"FtpGetFile","wininet.dll","FtpGetFile",micLong, micString,micString,micInteger,micDWord,micDWord,micDWord
Extern.Declare micInteger,"FtpPutFile","wininet.dll","FtpPutFileA",micLong, micString, micString, micDWord
Extern.Declare micLong, "FtpSetCurrentDirectory","wininet.dll","FtpSetCurrentDirectoryA",micLong, micString
Extern.Declare micLong, "FtpCommand", "wininet.dll", "FtpCommandA", micLong,micLong, micInteger, micString, micInteger, micLong
Extern.Declare micLong, "FtpDeleteFile", "wininet.dll", "FtpDeleteFileA", micLong, micString
Extern.Declare micInteger, "InternetCloseHandle", "wininet.dll", "InternetCloseHandle", micLong

objInternet=Extern.InternetOpen("QTP_FTP", 1, vbNullChar, vbNullChar,0)

If objInternet <> 0 then
objConnect=Extern.InternetConnect(objInternet,"< server_ip >", DEFAULT_FTP_PORT,"< username >","< password >",1,0,0)

If objConnect <> 0 then

val = Extern.FtpSetCurrentDirectory(objConnect,"/")

remote_path = "< file path >"

val = Extern.FtpSetCurrentDirectory(objConnect, remote_path)
If val <> 0 Then

remote_file_name = "< file name >"

val=Extern.FtpGetFile(objConnect, remote_file_name,"< local_machine_path >,0,0,1,0)
'val=Extern.FtpPutFile(objConnect,sLocalFile,sRemoteFile,0)
'val = FtpDeleteFile( objConnect, remote_file_name)
If CBool(val) <> 0 then
pop.popup "Downloaded Successfully" , 2
Reporter.ReportEvent micPass,"FtpPutFile","File Downloaded Successfully"
else
Reporter.ReportEvent micFail,"FtpGetFile","Failed to download file"
pop.popup val , 2
end if
else
pop.popup "Failed to Set the Directory" , 2
Reporter.ReportEvent micFail,"FtpGetFile","Failed to Set the Directory"
End If
else
pop.popup "Failed to Connect server" , 2
Reporter.ReportEvent micFail,"FtpGetFile","Failed to Connect server"
end if

else
pop.popup "Internet Connection Not Opened" , 2
Reporter.ReportEvent micFail,"FtpGetFile","Internet Connection Not Opened"
end if

Extern.InternetCloseHandle(objConnect)
Extern.InternetCloseHandle(objInternet)
Set pop = Nothing

No comments:

Post a Comment