Sunday, July 4, 2010

FTPPutFile

Example of FTPPutFile

const service_ftp=1
const open_type_direct=1
const ftp_transfer_type_ascii=1

'Extern is a QuickTest object to declare an external functions
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, "FtpPutFile", "wininet.dll", "FtpPutFileA", micLong,_ micString, micString, 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.xxxxxx.co.in", 21,"euuuuu","ppppregs",1,0,0)

If hnd_connection=0 then
msgbox "Connection is Failed"
Else
msgbox "Connection is Successful"
End If

a=Extern.FtpPutFile(hnd_connection,"c:\untitled.bmp","/tmp/untitled1.bmp",1,0)
msgbox a

Extern.InternetCloseHandle(hnd_connection)
Extern.InternetCloseHandle(hnd_internet)

FtpPutFile stores a file on the FTP server. First parameter is the handle to the FTP session. Second parameter is the name of the file to be sent from the local system. Third parameter is the name of the file to be created on the remote system. Fourth parameter is the transfer type flags and the last parameter is used if we are using callbacks. As we are not using callbacks so it is kept at 0.

FtpPutFile returns TRUE if successful, or FALSE otherwise.

Also See:
QTP FTP Main Post
FTP InternetOpen
FTP InternetConnect
FTPGetFile
FTPOpenFile
FTPSetCurrentDirectory
FTPCreateDirectory
FTPRenameFile
FTPRemoveDirectory
FTPDeleteFile