tftp class
- Richard Chidiak
- Posts: 946
- Joined: Thu Oct 06, 2005 7:05 pm
- Location: France
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42511
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42511
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42511
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42511
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42511
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
- Antonio Linares
- Site Admin
- Posts: 42511
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
Antonio,
This code is
FUNCTION EnvArqFtp(cArq)
LOCAL oInternet,oFtp,nVezes:=0,lInter:=.F.
oInternet := TInternet():New()
oFTP := TFTP():New( "ip by server", oInternet,"usr","pass" )
MandaArq(CurDir()+"\"+cArq,"/public_html/sav/"+cArq,500,oFTP)
RETURN NIL
STATIC FUNCTION MandaArq(cArquivo,cRemote,nTam,oFtp)
LOCAL n,hSource,cBuffer:=Space( 6400 ),nBufSize:=6400,oFile
IF (hSource := FOpen( cArquivo )) < 0
RETURN .F.
ELSE
cBuffer := Space( 6400 )
nBufSize := 6400
SysRefresh()
oFile := TFtpFile():New( cRemote, oFTP )
IF Empty(oFile)
RETURN .F.
ELSE
oFile:OpenWrite()
FSeek( hSource, 0, 0 )
nTotal := 0
DO WHILE ( nBytes := FRead( hSource, @cBuffer, nBufSize ) ) > 0
nFeito := oFile:Write( SubStr( cBuffer, 1, nBytes ) )
SysRefresh()
nTotal += nBytes
ENDDO
oFile:End()
FClose( hSource )
ENDIF
ENDIF
RETURN .T.
This code is
FUNCTION EnvArqFtp(cArq)
LOCAL oInternet,oFtp,nVezes:=0,lInter:=.F.
oInternet := TInternet():New()
oFTP := TFTP():New( "ip by server", oInternet,"usr","pass" )
MandaArq(CurDir()+"\"+cArq,"/public_html/sav/"+cArq,500,oFTP)
RETURN NIL
STATIC FUNCTION MandaArq(cArquivo,cRemote,nTam,oFtp)
LOCAL n,hSource,cBuffer:=Space( 6400 ),nBufSize:=6400,oFile
IF (hSource := FOpen( cArquivo )) < 0
RETURN .F.
ELSE
cBuffer := Space( 6400 )
nBufSize := 6400
SysRefresh()
oFile := TFtpFile():New( cRemote, oFTP )
IF Empty(oFile)
RETURN .F.
ELSE
oFile:OpenWrite()
FSeek( hSource, 0, 0 )
nTotal := 0
DO WHILE ( nBytes := FRead( hSource, @cBuffer, nBufSize ) ) > 0
nFeito := oFile:Write( SubStr( cBuffer, 1, nBytes ) )
SysRefresh()
nTotal += nBytes
ENDDO
oFile:End()
FClose( hSource )
ENDIF
ENDIF
RETURN .T.
- Antonio Linares
- Site Admin
- Posts: 42511
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 31 times
- Been thanked: 73 times
- Contact:
Vilian,
We have tested your sample and checked these values:
MsgInfo( oFTP:hFTP )
MsgInfo( oFile:hFile )
they look ok, but InternetWriteFile() (oFile:Write()) is returning 0x87 for GetLastError(): ERROR_INVALID_PARAMETER
We don't know why it reports such value![Sad :-(](./images/smilies/icon_sad.gif)
Have you tried to use FtpPutFile() instead of sending blocks ?
We have tested your sample and checked these values:
MsgInfo( oFTP:hFTP )
MsgInfo( oFile:hFile )
they look ok, but InternetWriteFile() (oFile:Write()) is returning 0x87 for GetLastError(): ERROR_INVALID_PARAMETER
We don't know why it reports such value
![Sad :-(](./images/smilies/icon_sad.gif)
Have you tried to use FtpPutFile() instead of sending blocks ?