I am trying to send a file to a FTP server and it appears to work (ie: no errors) and it does create a file name on the server but the size is always 0KB.
The size should be 1,560KB
The code is below.
Can someone please tell me where I am going wrong?
- Code: Select all Expand view
FUNCTION FtpSendFile( cFTPSite, cSource, cTarget, cUser, cPass, nBufSize )
LOCAL oInternet, oFTP
DEFAULT cUser:="", cPass:="", nBufSize:=2000
IF EMPTY(cFtpSite) .or. EMPTY(cSource) .or. EMPTY(cTarget)
MsgInfo("Missing Parameters"+chr(13)+"Usage: FtpSendFile(cFtpSite, cSource, cTarget, cUser, cPass, nBufSize) ","FtpSendFile()")
Return .f.
ENDIF
oInternet := TInternet():New()
IF Empty( oInternet:hSession )
MsgAlert( "Internet session not available!" )
ELSE
oFTP := TFTP():New( cFTPSite, oInternet, cUser, cPass )
IF Empty( oFTP:hFTP )
MsgStop( "Cannot connect to "+cFtpSite )
oInternet:End()
return .f.
ENDIF
ENDIF
SendFiles( cSource, cTarget, nBufSize, oFTP )
Syswait(.05)
oInternet:End()
return .t.
static function SendFiles( cSource, cTarget, nBufSize, oFTP )
local hSource
local cBuffer := Space( nBufSize )
local nBytes
local oFile
if ! File( cSource )
MsgStop( "File not found: " + cSource )
Return .f.
endif
hSource = FOpen( cSource )
oFile = TFtpFile():New( cTarget, oFTP )
oFile:OpenWrite()
FSeek( hSource, 0, 0 )
nFile := 0
SysRefresh()
while ( nBytes := FRead( hSource, @cBuffer, nBufSize ) ) > 0
oFile:Write( SubStr( cBuffer, 1, nBytes ) )
SysRefresh()
end
FClose( hSource )
oFile:End()
return .t.