fb:porticula NoPaste
wininet ftp test
Uploader: | Eternal_Pain |
Datum/Zeit: | 11.07.2007 19:25:07 |
#include once "win/wininet.bi"
type ftp_ctx
as HINTERNET hint, hconn
end type
Declare function ftp_open( byval ctx as ftp_ctx ptr, byval ctrlname as string = "FTP Nameless Control", byval accesstype as integer = INTERNET_OPEN_TYPE_DIRECT, byval proxyname as string = "", byval proxybypass as string = "") as integer
Declare function ftp_putfile( byval ctx as ftp_ctx ptr, byval remotefile as string, byval localfile as string, byval mode as integer = FTP_TRANSFER_TYPE_BINARY) as integer
Declare function ftp_close( byval ctx as ftp_ctx ptr ) as integer
Declare function ftp_connect( byval ctx as ftp_ctx ptr, byval servername as string, byval serverport as integer = INTERNET_DEFAULT_FTP_PORT, byval username as string = "anonymous", byval useremail as string = "anonymous@anonymous", byval ispassive as integer = FALSE) as integer
'***************************************************************************
function ftp_putfile( byval ctx as ftp_ctx ptr, _
byval remotefile as string, _
byval localfile as string, _
byval mode as integer = FTP_TRANSFER_TYPE_BINARY _
) as integer
'***************************************************************************
if( ctx->hconn = NULL ) then
return FALSE
end if
function = FtpPutFile( ctx->hconn, remotefile, localfile, mode, NULL )
'***************************************************************************
end function
'***************************************************************************
'***************************************************************************
function ftp_close( byval ctx as ftp_ctx ptr ) as integer
'***************************************************************************
if( ctx->hconn <> NULL ) then
InternetCloseHandle( ctx->hconn )
ctx->hconn = NULL
end if
if( ctx->hint <> NULL ) then
InternetCloseHandle( ctx->hint )
ctx->hint = NULL
end if
function = TRUE
'***************************************************************************
end function
'***************************************************************************
'***************************************************************************
function ftp_connect( byval ctx as ftp_ctx ptr, _
byval servername as string, _
byval serverport as integer = INTERNET_DEFAULT_FTP_PORT, _
byval username as string = "anonymous", _
byval useremail as string = "anonymous@anonymous", _
byval ispassive as integer = FALSE _
) as integer
'***************************************************************************
if( ftp_open( ctx ) = FALSE ) then
return FALSE
end if
ctx->hconn = InternetConnect( ctx->hint, _
servername, serverport, _
username, useremail, _
INTERNET_SERVICE_FTP, _
iif( ispassive <> FALSE, 0, 0 ), _
NULL )
if( ctx->hconn = NULL ) then
InternetCloseHandle( ctx->hint )
ctx->hint = NULL
return FALSE
end if
function = TRUE
'***************************************************************************
end function
'***************************************************************************
'***************************************************************************
function ftp_open( byval ctx as ftp_ctx ptr, _
byval ctrlname as string = "FTP Nameless Control", _
byval accesstype as integer = INTERNET_OPEN_TYPE_DIRECT, _
byval proxyname as string = "", _
byval proxybypass as string = "" _
) as integer
'***************************************************************************
if( ctx->hint <> NULL ) then
return TRUE
end if
ctx->hint = InternetOpen( ctrlname, accesstype, proxyname, proxybypass, 0 )
if( ctx->hint = NULL ) then
return FALSE
end if
function = TRUE
'***************************************************************************
end function
'***************************************************************************
type testxyz
Host as string
Name as string
Pass as String
End Type
Dim FTP_Dat as testxyz
FTP_Dat.Host="HOST"
FTP_Dat.Name="NAME"
FTP_Dat.Pass="PASS"
dim rssName as String
rssName="Filename.ext"
Dim ftp as ftp_ctx
if( ftp_connect( @ftp, FTP_Dat.Host,21,FTP_Dat.Name,FTP_Dat.Pass ) = FALSE ) then
print "ERROR: Calling ftp_connect()"
ftp_close( @ftp ):sleep:end
Else
?"connect "+FTP_Dat.Host
End If
?"write "+rssName
if( ftp_putfile( @ftp, rssName, rssName, FTP_TRANSFER_TYPE_ASCII ) = FALSE ) then
print "ERROR: Calling ftp_putfile()"
ftp_close( @ftp ):sleep:end
end if
ftp_close( @ftp )
sleep