2007-07-17 16:48 UTC+0100 Miguel Angel Marchuet <miguelangel/at/marchuet.net>
* source/tip/client.prg
* source/tip/ftpcln.prg
+ Added support to PORT transfer mode, alternative to PASV transfer mode. When :bUsePasv will be false
PORT mode will be used. and cleaned some unused variables.
+ Added method :NoOp()
+ Added method :Rest( nPos )
* Changed method :LS( cSpec )
* Changed method :List( cSpec )
* Changed method :TransferStart()
* Changed method :Stor( cFile )
* Changed method :UploadFile( cLocalFile, cRemoteFile )
* Changed method :DownloadFile( cLocalFile, cRemoteFile )
+ Added method :Port()
+ Added method :SendPort()
This commit is contained in:
@@ -8,6 +8,22 @@
|
||||
2002-12-01 13:30 UTC+0100 Foo Bar <foo.bar@foobar.org>
|
||||
*/
|
||||
|
||||
2007-07-17 16:48 UTC+0100 Miguel Angel Marchuet <miguelangel/at/marchuet.net>
|
||||
* source/tip/client.prg
|
||||
* source/tip/ftpcln.prg
|
||||
+ Added support to PORT transfer mode, alternative to PASV transfer mode. When :bUsePasv will be false
|
||||
PORT mode will be used. and cleaned some unused variables.
|
||||
+ Added method :NoOp()
|
||||
+ Added method :Rest( nPos )
|
||||
* Changed method :LS( cSpec )
|
||||
* Changed method :List( cSpec )
|
||||
* Changed method :TransferStart()
|
||||
* Changed method :Stor( cFile )
|
||||
* Changed method :UploadFile( cLocalFile, cRemoteFile )
|
||||
* Changed method :DownloadFile( cLocalFile, cRemoteFile )
|
||||
+ Added method :Port()
|
||||
+ Added method :SendPort()
|
||||
|
||||
2007-07-16 9:02 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
|
||||
* common.mak
|
||||
* makefile.vc
|
||||
|
||||
@@ -348,7 +348,7 @@ METHOD ReadToFile( cFile, nMode, nSize ) CLASS tIPClient
|
||||
|
||||
ENDDO
|
||||
|
||||
IF nSent >0
|
||||
IF nSent > 0
|
||||
::Commit()
|
||||
Endif
|
||||
|
||||
|
||||
@@ -63,11 +63,30 @@
|
||||
Added method UserCommand( cCommand, lPasv, lReadPort, lGetReply )
|
||||
*/
|
||||
|
||||
/* 2007-07-12, miguelangel@marchuet.net
|
||||
Added method :NoOp()
|
||||
Added method :Rest( nPos )
|
||||
Changed method :LS( cSpec )
|
||||
Changed method :List( cSpec )
|
||||
Changed method :TransferStart()
|
||||
Changed method :Stor( cFile )
|
||||
Changed method :UploadFile( cLocalFile, cRemoteFile )
|
||||
Changed method :DownloadFile( cLocalFile, cRemoteFile )
|
||||
|
||||
Added support to Port transfer mode
|
||||
Added method :Port()
|
||||
Added method :SendPort()
|
||||
|
||||
Cleaned unused variables.
|
||||
*/
|
||||
|
||||
#include "directry.ch"
|
||||
#include "hbclass.ch"
|
||||
#include "tip.ch"
|
||||
#include "common.ch"
|
||||
|
||||
STATIC nPort := 16000
|
||||
|
||||
/**
|
||||
* Inet service manager: ftp
|
||||
*/
|
||||
@@ -80,8 +99,9 @@ CLASS tIPClientFTP FROM tIPClient
|
||||
DATA RegPasv
|
||||
// Socket opened in response to a port command
|
||||
DATA SocketControl
|
||||
DATA SocketPortServer
|
||||
|
||||
METHOD New( oUrl,lTrace, oCredentials)
|
||||
METHOD New( oUrl, lTrace, oCredentials )
|
||||
METHOD Open()
|
||||
METHOD Read( nLen )
|
||||
METHOD Write( nLen )
|
||||
@@ -93,19 +113,21 @@ CLASS tIPClientFTP FROM tIPClient
|
||||
METHOD Pasv()
|
||||
METHOD TypeI()
|
||||
METHOD TypeA()
|
||||
METHOD List()
|
||||
METHOD NoOp()
|
||||
METHOD Rest( nPos )
|
||||
METHOD List( cSpec )
|
||||
METHOD UserCommand( cCommand, lPasv, lReadPort, lGetReply )
|
||||
METHOD pwd()
|
||||
METHOD Cwd()
|
||||
METHOD Dele()
|
||||
//METHOD Port()
|
||||
//METHOD SendPort()
|
||||
METHOD Retr()
|
||||
METHOD Stor()
|
||||
METHOD Pwd()
|
||||
METHOD Cwd( cPath )
|
||||
METHOD Dele( cPath )
|
||||
METHOD Port()
|
||||
METHOD SendPort()
|
||||
METHOD Retr( cFile )
|
||||
METHOD Stor( cFile )
|
||||
METHOD Quit()
|
||||
METHOD ScanLength()
|
||||
METHOD ReadAuxPort()
|
||||
method mget()
|
||||
METHOD mget()
|
||||
// Method bellow contributed by Rafa Carmona
|
||||
|
||||
METHOD LS( cSpec )
|
||||
@@ -246,11 +268,23 @@ METHOD TypeA() CLASS tIPClientFTP
|
||||
RETURN ::GetReply()
|
||||
|
||||
|
||||
METHOD NoOp() CLASS tIPClientFTP
|
||||
::InetSendall( ::SocketCon, "NOOP" + ::cCRLF )
|
||||
RETURN ::GetReply()
|
||||
|
||||
|
||||
METHOD Rest( nPos ) CLASS tIPClientFTP
|
||||
::InetSendall( ::SocketCon, "REST " + Str( If( Empty( nPos ), 0, nPos ),,, .T. ) + ::cCRLF )
|
||||
RETURN ::GetReply()
|
||||
|
||||
|
||||
METHOD CWD( cPath ) CLASS tIPClientFTP
|
||||
::InetSendall( ::SocketCon, "CWD " + cPath + ::cCRLF )
|
||||
RETURN ::GetReply()
|
||||
|
||||
|
||||
METHOD PWD() CLASS tIPClientFTP
|
||||
|
||||
::InetSendall( ::SocketCon, "PWD" + ::cCRLF )
|
||||
IF .not. ::GetReply()
|
||||
RETURN .F.
|
||||
@@ -259,6 +293,7 @@ METHOD PWD() CLASS tIPClientFTP
|
||||
Rat('"', ::cReply) - At('"', ::cReply) - 1 )
|
||||
RETURN .T.
|
||||
|
||||
|
||||
METHOD DELE( cPath ) CLASS tIPClientFTP
|
||||
::InetSendall( ::SocketCon, "DELE " + cPath + ::cCRLF )
|
||||
RETURN ::GetReply()
|
||||
@@ -282,7 +317,7 @@ METHOD TransferStart() CLASS tIPClientFTP
|
||||
skt := InetConnectIP( ::cDataServer, ::nDataPort )
|
||||
IF skt != NIL .and. ::InetErrorCode( skt ) == 0
|
||||
// Get the start message from the control connection
|
||||
IF .not. ::GetReply()
|
||||
IF ! ::GetReply()
|
||||
InetClose( skt )
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
@@ -290,18 +325,24 @@ METHOD TransferStart() CLASS tIPClientFTP
|
||||
InetSetTimeout( skt, ::nConnTimeout )
|
||||
::SocketCon := skt
|
||||
ENDIF
|
||||
/*ELSE
|
||||
::SocketCon := InetAccept( ::SocketPortServer )*/
|
||||
ELSE
|
||||
::SocketCon := InetAccept( ::SocketPortServer )
|
||||
IF Empty( ::SocketCon )
|
||||
::bInitialized := .F.
|
||||
::SocketCon := ::SocketControl
|
||||
::GetReply()
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
RETURN .T.
|
||||
|
||||
|
||||
|
||||
METHOD Commit() CLASS tIPClientFTP
|
||||
InetClose( ::SocketCon )
|
||||
::SocketCon := ::SocketControl
|
||||
::bInitialized := .F.
|
||||
|
||||
IF .not. ::GetReply()
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
@@ -310,20 +351,17 @@ METHOD Commit() CLASS tIPClientFTP
|
||||
IF ::cReply[1] == "5"
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
/*
|
||||
IF ::GetReply() .and. ::cReply[1] != "5"
|
||||
RETURN .T.
|
||||
ENDIF*/
|
||||
|
||||
RETURN .T.
|
||||
|
||||
|
||||
METHOD List(cSpec) CLASS tIPClientFTP
|
||||
METHOD List( cSpec ) CLASS tIPClientFTP
|
||||
LOCAL cStr
|
||||
|
||||
IF cSpec=nil
|
||||
cSpec:=''
|
||||
cSpec := ''
|
||||
else
|
||||
cSpec:=' '+cSpec
|
||||
cSpec := ' ' + cSpec
|
||||
ENDIF
|
||||
IF ::bUsePasv
|
||||
IF .not. ::Pasv()
|
||||
@@ -332,13 +370,13 @@ METHOD List(cSpec) CLASS tIPClientFTP
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
/* IF .not. ::bUsePasv
|
||||
IF .not. ::bUsePasv
|
||||
IF .not. ::Port()
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
ENDIF
|
||||
*/
|
||||
::InetSendAll( ::SocketCon, "LIST"+cSpec + ::cCRLF )
|
||||
|
||||
::InetSendAll( ::SocketCon, "LIST" + cSpec + ::cCRLF )
|
||||
cStr := ::ReadAuxPort()
|
||||
::bEof := .f.
|
||||
RETURN cStr
|
||||
@@ -364,7 +402,7 @@ METHOD UserCommand( cCommand, lPasv, lReadPort, lGetReply ) CLASS tIPClientFTP
|
||||
lGetReply = ::GetReply()
|
||||
endif
|
||||
|
||||
return .t.
|
||||
RETURN .t.
|
||||
|
||||
|
||||
METHOD ReadAuxPort(cLocalFile) CLASS tIPClientFTP
|
||||
@@ -398,7 +436,6 @@ METHOD ReadAuxPort(cLocalFile) CLASS tIPClientFTP
|
||||
RETURN NIL
|
||||
|
||||
|
||||
|
||||
METHOD Stor( cFile ) CLASS tIPClientFTP
|
||||
|
||||
IF ::bUsePasv
|
||||
@@ -408,15 +445,18 @@ METHOD Stor( cFile ) CLASS tIPClientFTP
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
::InetSendall( ::SocketCon, "STOR " + cFile+ ::cCRLF )
|
||||
::InetSendall( ::SocketCon, "STOR " + cFile + ::cCRLF )
|
||||
IF ! ::GetReply()
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
|
||||
RETURN ::TransferStart()
|
||||
|
||||
/*
|
||||
|
||||
METHOD Port() CLASS tIPClientFTP
|
||||
LOCAL nPort := 16000
|
||||
|
||||
::SocketPortServer := InetCreate( ::nConnTimeout )
|
||||
nPort ++
|
||||
DO WHILE nPort < 24000
|
||||
InetServer( nPort, ::SocketPortServer )
|
||||
IF ::InetErrorCode( ::SocketPortServer ) == 0
|
||||
@@ -424,23 +464,22 @@ METHOD Port() CLASS tIPClientFTP
|
||||
ENDIF
|
||||
nPort ++
|
||||
ENDDO
|
||||
::SocketPortServer := NIL
|
||||
|
||||
RETURN .F.
|
||||
|
||||
|
||||
METHOD SendPort() CLASS tIPClientFTP
|
||||
LOCAL cAddr
|
||||
LOCAL cPort, nPort
|
||||
|
||||
cAddr := InetAddress( ::SocketPortServer )
|
||||
cAddr := InetGetHosts( NetName() )[1]
|
||||
cAddr := StrTran( cAddr, ".", "," )
|
||||
nPort := InetPort( ::SocketPortServer )
|
||||
cPort := "," + AllTrim( Str ( Int( nPort / 256 ) ) ) + "," + AllTrim( Str ( nPort % 256 ) )
|
||||
cPort := "," + AllTrim( Str( Int( nPort / 256 ) ) ) + "," + AllTrim( Str( Int( nPort % 256 ) ) )
|
||||
|
||||
? "PORT " + cAddr + cPort
|
||||
::InetSendall( ::SocketCom, "PORT " + cAddr + cPort + ::cCRLF )
|
||||
::InetSendall( ::SocketCon, "PORT " + cAddr + cPort + ::cCRLF )
|
||||
RETURN ::GetReply()
|
||||
*/
|
||||
|
||||
|
||||
METHOD Read( nLen ) CLASS tIPClientFTP
|
||||
LOCAL cRet
|
||||
@@ -531,7 +570,7 @@ METHOD Retr( cFile ) CLASS tIPClientFTP
|
||||
ENDIF
|
||||
ENDIF
|
||||
|
||||
::InetSendAll( ::SocketCon, "RETR " + cFile+ ::cCRLF )
|
||||
::InetSendAll( ::SocketCon, "RETR " + cFile + ::cCRLF )
|
||||
|
||||
IF ::TransferStart()
|
||||
::ScanLength()
|
||||
@@ -600,7 +639,7 @@ METHOD UpLoadFile( cLocalFile, cRemoteFile ) CLASS tIPClientFTP
|
||||
|
||||
HB_FNameSplit( cLocalFile, @cPath, @cFile,@cExt )
|
||||
|
||||
DEFAULT cRemoteFile to cFile+cExt
|
||||
DEFAULT cRemoteFile to cFile + cExt
|
||||
|
||||
::bEof := .F.
|
||||
::oUrl:cFile := cRemoteFile
|
||||
@@ -613,15 +652,19 @@ METHOD UpLoadFile( cLocalFile, cRemoteFile ) CLASS tIPClientFTP
|
||||
|
||||
ENDIF
|
||||
|
||||
IF .not. Empty( ::oUrl:cPath )
|
||||
IF ! Empty( ::oUrl:cPath )
|
||||
|
||||
IF .not. ::CWD( ::oUrl:cPath )
|
||||
IF ! ::CWD( ::oUrl:cPath )
|
||||
RETURN -1
|
||||
ENDIF
|
||||
|
||||
ENDIF
|
||||
|
||||
IF .not. ::Stor( ::oUrl:cFile )
|
||||
IF ! ::bUsePasv .AND. ! ::Port()
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
|
||||
IF ! ::Stor( ::oUrl:cFile )
|
||||
RETURN -1
|
||||
ENDIF
|
||||
|
||||
@@ -634,25 +677,27 @@ RETURN ::WriteFromFile( cLocalFile )
|
||||
|
||||
METHOD LS( cSpec ) CLASS tIPClientFTP
|
||||
|
||||
LOCAL cStr
|
||||
LOCAL cStr
|
||||
|
||||
IF cSpec == nil
|
||||
cSpec := ''
|
||||
ENDIF
|
||||
IF cSpec == nil
|
||||
cSpec := ''
|
||||
ENDIF
|
||||
|
||||
IF ::bUsePasv
|
||||
IF ::bUsePasv .AND. ! ::Pasv()
|
||||
//::bUsePasv := .F.
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
|
||||
IF .not. ::Pasv()
|
||||
IF ! ::bUsePasv .AND. ! ::Port()
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
|
||||
//::bUsePasv := .F.
|
||||
RETURN .F.
|
||||
|
||||
ENDIF
|
||||
|
||||
ENDIF
|
||||
|
||||
::InetSendAll( ::SocketCon, "NLST "+cSpec + ::cCRLF )
|
||||
cStr := ::ReadAuxPort()
|
||||
::InetSendAll( ::SocketCon, "NLST " + cSpec + ::cCRLF )
|
||||
IF ::GetReply()
|
||||
cStr := ::ReadAuxPort()
|
||||
ELSE
|
||||
cStr := ''
|
||||
ENDIF
|
||||
|
||||
RETURN cStr
|
||||
|
||||
@@ -670,15 +715,15 @@ METHOD Rename( cFrom, cTo ) CLASS tIPClientFTP
|
||||
|
||||
ENDIF
|
||||
|
||||
Return lResult
|
||||
RETURN lResult
|
||||
|
||||
METHOD DownLoadFile( cLocalFile, cRemoteFile ) CLASS tIPClientFTP
|
||||
|
||||
Local cPath := ""
|
||||
Local cFile := ""
|
||||
Local cExt := ""
|
||||
LOCAL cPath := ""
|
||||
LOCAL cFile := ""
|
||||
LOCAL cExt := ""
|
||||
|
||||
HB_FNameSplit( cLocalFile, @cPath, @cFile,@cExt )
|
||||
HB_FNameSplit( cLocalFile, @cPath, @cFile, @cExt )
|
||||
|
||||
|
||||
DEFAULT cRemoteFile to cFile+cExt
|
||||
@@ -686,16 +731,18 @@ METHOD DownLoadFile( cLocalFile, cRemoteFile ) CLASS tIPClientFTP
|
||||
::bEof := .F.
|
||||
::oUrl:cFile := cRemoteFile
|
||||
|
||||
IF .not. ::bInitialized
|
||||
IF ! ::bInitialized
|
||||
|
||||
IF .not. Empty( ::oUrl:cPath )
|
||||
IF .not. ::CWD( ::oUrl:cPath )
|
||||
::bEof = .T. // no data for this transaction
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
IF ! Empty( ::oUrl:cPath ) .AND. ! ::CWD( ::oUrl:cPath )
|
||||
::bEof = .T. // no data for this transaction
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
|
||||
IF .not. ::Retr( ::oUrl:cFile )
|
||||
IF ! ::bUsePasv .AND. ! ::Port()
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
|
||||
IF ! ::Retr( ::oUrl:cFile )
|
||||
::bEof = .T. // no data for this transaction
|
||||
RETURN .F.
|
||||
ENDIF
|
||||
|
||||
Reference in New Issue
Block a user