Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #8308
| From | "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it> |
|---|---|
| Newsgroups | comp.lang.clipper.visual-objects |
| Subject | Re: Secure FTP or SFTP support in VO |
| Date | 2015-07-29 16:42 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <mpaola$8nc$1@dont-email.me> (permalink) |
| References | (1 earlier) <d1e6ufFpqi6U1@mid.individual.net> <mp4isp$el4$1@dont-email.me> <3ddcfeca-eede-448a-bca7-323f00259335@googlegroups.com> <mp9v9n$ca0$1@dont-email.me> <11919010-a31e-4ca9-be6a-e895bab1877e@googlegroups.com> |
I use also WinSCP. currently in VO calling WINSCP with a batchjob created at
runtime. Better would be a dotnet solution but this has to wait a little
bit.
Arne Ortlinghaus
ACS Data Systems
---------------------- Example
class -----------------------------------------------------------
class clsFTPWinSCP
protect _nerror as int
protect _cLastStatusMsg, _cerror, _ccommands as string
protect _oOwner as CFTPUniversal
protect _aresult as array
protect _cparams, _cmode, _cftp, _cuser, _cpassword, _cdir as string
protect _nport as int
protect _adeletetempfiles, _adirstackNew , _adirstack as array
protect _ldebug, _laddcommandsbefore as logic
protect _cPutmodeparam, _cPutmode, _cExecutionimmediatemode as string
declare method AddCommand, CheckExecute, setconnectionparameters, Execute,
decoderesult, seterror, AddDirstack
declare method AddOpen, PostExecute, SetCurDir, SetCurDirInternal,
__DeleteTempfiles, __Createtempfile
declare assign lSafeFTPFileTransfer
access Error class clsFTPWinSCP
return _nerror
method Axit () class clsFTPWinSCP
self:Close()
return nil
method Close() class clsFTPWinSCP
self:__DeleteTempfiles()
UnRegisterAxit(self)
return nil
method CreateDir (cRemoteDir) class clsFTPWinSCP
// mkdir Creates remote directory
self:AddCommand('mkdir "'+cRemoteDir+'"')
return self:CheckExecute("CreateDir")
method DeleteFile (cRemoteFile) class clsFTPWinSCP
//rm Removes remote file
self:AddCommand('rm "'+cRemoteFile+'"')
return self:CheckExecute("DELETEFILE")
method AddCommand(ccommand as string) as void pascal class clsFTPWinSCP
if _laddcommandsbefore
_ccommands := ccommand + crlf+_ccommands
else
_ccommands += ccommand + crlf
endif
return
access ErrorMsg class clsFTPWinSCP
return _cerror
method Reset() class clsFTPWinSCP
_cerror := ""
_nerror := 0
_adirstack := {}
_adirstackNew := {}
_adeletetempfiles := {}
return nil
access aresult class clsFTPWinSCP
return _aresult
method Directory (cFile) class clsFTPWinSCP
// ls Lists the contents of remote directory
local aret as array
aret := {}
// Todo 91901 AO 2015-06-10 17:42 Vulcan, Ersatz ACSINET
// Fehler, wenn z.B. Directory ("Updcat.ini")
if !Instr("*", cFile)
cFile := cFile+"*"
endif
self:AddCommand('ls '+cFile)
if self:CheckExecute("Directory")
aret := self:aresult
endif
return aret
method GetFile (cRemoteFile, cNewFile) class clsFTPWinSCP
// Downloads one or more files from remote directory to local directory.
// get <file> [ [ <file2> ... ] <directory>\[ <newname> ] ]
self:AddCommand('get "'+cRemoteFile+'" "'+cNewFile+'"')
return self:CheckExecute("GetFile")
method GetCurDir () class clsFTPWinSCP
return "?"
method PutFileEx (cLocalFile, cRemoteFile) class clsFTPWinSCP
// put Uploads file from local directory to remote directory
//put <file> [ [ <file2> ... ] <directory>/[ <newname> ] ]
// {"Rename if possible", "RENAME"},;
// {"No control", "NONE"},;
// {"Additional zero byte file same name, different extension",
"ADDFILEEXT"},;
// {"Additional zero byte file same name, different directory",
"ADDFILEDIR"};
local cTempFile as string
local i, nsubdirs as dword
if _cPutmode == "NONE"
// Todo 90524 AO 2015-05-13 09:14 McD USA FTP->SFTP
// resumesupport=off notwendig, wenn rename nicht erlaubt
// -nopreservetime -nopermissions wenn setzen von Datetime und Setzen von
Permissions nicht möglich
// beides zusammengemacht, weil ausgegangen werden kann, dass es ein
restriver FTP-Server ist
self:AddCommand('put "'+cLocalFile+'" "'+cRemoteFile+'"'+
" -resumesupport=off -nopreservetime -nopermissions")
elseif _cPutmode == "RENAME"
cTempFile := cRemoteFile+"*" // Löschen einer Datei, die möglicherweise
da ist. * damit keine Fehlermeldung, falls nicht existiert
self:AddCommand('rm "'+cTempFile+'"')
cTempFile := "-"+FGetFileName(cRemoteFile) + ".TMP"
self:AddCommand('put "'+cLocalFile+'" "'+cTempFile+'"') // Schreiben mit
anderem Namen
self:AddCommand('mv "'+cTempFile+'" "'+cRemoteFile+'"') // umbenennen
elseif _cPutmode == "ADDFILEEXT"
cTempFile := Fgettempdir()+fchangeext(FGetFileNameAndext(cLocalFile),
_cPutmodeparam)
self:__Createtempfile(cTempFile)
self:AddCommand('put "'+cLocalFile+'" "'+cRemoteFile+'"')
self:AddCommand('put "'+cTempFile+'" "'+FChangeExt(cRemoteFile,
_cPutmodeparam)+'"')
elseif _cPutmode == "ADDFILEDIR"
self:AddCommand('put "'+cLocalFile+'" "'+cRemoteFile+'"')
if !Empty(_cdir)
nsubdirs := Occurs("/", _cdir)+1
for i := 1 upto nsubdirs
self:AddCommand('cd ..')
next
endif
self:AddCommand('cd "'+_cPutmodeparam+'"')
cTempFile := FGetTempDir()+FGetFileNameandExt(cLocalFile)
self:__Createtempfile(cTempFile)
self:AddCommand('put "'+cTempFile+'"
"'+FGetFileNameandExt(cTempFile)+'"')
nsubdirs := Occurs("/", _cPutmodeparam)+1
for i := 1 upto nsubdirs
self:AddCommand('cd ..')
next
if !Empty(_cdir)
self:AddCommand('cd "'+_cdir+'"')
endif
else
self:seterror ("Missing parameter Putmode " +
TypeValue2String(_cPutmode))
endif
return self:CheckExecute("PUTFILE")
method RemoveDir (cRemoteDir) class clsFTPWinSCP
// rmdir Removes remote directory
self:AddCommand('rmdir "'+cRemoteDir+'"')
return self:CheckExecute("RemoveDir")
method RenameFile (cRemoteFile, cNewName) class clsFTPWinSCP
// Moves or renames one or more remote files.
// mv <file> [ <file2> ... ] [ <directory>/ ][ <newname> ]
self:AddCommand('mv "'+cRemoteFile+'" "'+cNewName+'"')
return self:CheckExecute("RENAMEFILE")
method SetCurDir (cRemoteDir as string) as logic pascal class clsFTPWinSCP
// cd Changes remote working directory
local i as dword
local a as array
a := String2Array(cRemoteDir, "/")
for i := 1 upto ALen(a)
if !Empty(a[i])
AAdd (_adirstackNew, a[i])
endif
next
return self:SetCurDirInternal(cRemoteDir)
method Init(oOwner) class clsFTPWinSCP
_oOwner := oOwner
self:Reset()
return self
method setconnectionparameters (cmode as string, cftp as string, cuser as
string, cpassword as string, cdir as string, cparams as string, nport as
int, lDebug as logic, cExecutionimmediatemode as string, cPutmode as string,
cPutmodeparam as string) as void pascal class clsFTPWinSCP
self:Reset()
_cmode := cmode
_cftp := cftp
_cuser := cuser
_cpassword := cpassword
_cdir := cdir
_cparams := cparams
_nport := nport
_ldebug := lDebug
_cExecutionimmediatemode := cExecutionimmediatemode
_cPutmode := cPutmode
_cPutmodeparam := cPutmodeparam
if !Empty(_cdir)
self:SetCurDir(_cdir)
endif
return
method CheckExecute(ccommand as string) as logic pascal class clsFTPWinSCP
local l, lok as logic
lok := true
ccommand := Upper (ccommand)
if _ldebug
DebugOut ("FTPWinSCP:CheckExecute: " + ccommand)
endif
if _cExecutionimmediatemode == "ALL"
l := InList (ccommand, "ALL", "GETFILE", "DIRECTORY", "PUTFILE",
"DELETEFILE", "RENAMEFILE")
else
l := InList (ccommand, "ALL", "GETFILE", "DIRECTORY")
endif
if l .and. !Empty(_ccommands)
lok := self:Execute(ccommand)
endif
return lok
access LastStatusMsg class clsFTPWinSCP
return _cLastStatusMsg
method Execute(ccommand as string) as logic pascal class clsFTPWinSCP
local c, cargs, cfilelog, cfileparams, cexefile as string
local lok as logic
//local oSpawnProcess as object
lok := true
_aresult := {}
cexefile := FGetExeDir() +"WinSCP.exe"
if !FExist(cexefile)
self:seterror("FTP Exefile not found: " +cexefile)
return false
endif
sncounter_WinSCP += 1
cfileparams := fgettempdir() +"FTP" +getserverdatetime(5)
+ntrim(sncounter_WinSCP) +".txt"
self:AddDirstack()
self:AddOpen()
self:AddCommand("exit")
if !fFileWrite(cfileparams, _ccommands)
self:seterror("Temporary Parameter file could not be written")
return false
endif
cfilelog := FChangeExt(cfileparams, ".log")
if FExist(cfilelog)
if !FDeleteFile(cfilelog)
self:seterror("Temporary Parameter file could not be written")
return false
endif
endif
cargs := '/console ' +'/script="' +cfileparams +'" /xmllog="' +cfilelog +'"
/ini=nul'
if _ldebug
MsgInfo ("FTP Debug before calling
Winscp.exe"+crlf+cfileparams+crlf+_ccommands+crlf+cexefile+crlf+cargs)
endif
lok := fspawnprocess(cexefile, cargs, nil, fgettempdir(), "WAIT")
// oSpawnProcess := CreateInstance(#SpawnProcess,nil,cexefile+ " " + cargs,
nil, FGetTempDir())
// lok := oSpawnProcess:spawnedOk
FDeleteFile(cfileparams)
if !lok
self:seterror("FTP Exe could not be started" + crlf+cexefile+crlf+cargs)
return false
endif
// lok := oSpawnProcess:waitUntilFinishedProgress(_oOwner, "FTP Access",
cfilelog, {})
// oSpawnProcess:Destroy()
// if !lok
// self:seterror("FTP Execution cancelled" + crlf+cexefile+crlf+cargs)
// return false
// endif
if !FExist(cfilelog)
self:seterror("Logfile from FTP Exe file not found" +
crlf+cexefile+crlf+cargs+crlf+cfilelog)
return false
endif
c := fFileRead(cfilelog)
c := ConvertUnicodeString(c,#CodepageToAnsi, 65001)
if _ldebug
MsgInfo ("FTP Debug after calling Winscp.exe analyzing
logfile"+crlf+c+crlf+cfilelog)
endif
FDeleteFile(cfilelog)
lok := self:decoderesult(ccommand, c)
self:PostExecute()
return lok
static global sncounter_WinSCP as int
method decoderesult (ccommand as string, c as string) as logic pascal class
clsFTPWinSCP
local afile, a as array
local i as dword
local ct as string
local d as date
if At("<failure>", c) > 0
a := StringExtract2Array(c, "<failure>", "</failure>", "")
_cerror := a[1]
_cerror := StrTran(_cerror, "<message>", "")
_cerror := StrTran(_cerror, "</message>", "")
a := StringExtract2Array(_cerror, "Host key fingerprint is ", ".",
"EMPTYIFERRORS")
if !Empty(a)
if ALen(a) >= 1 .and. !Empty(a[1])
_cerror += crlf+"This is an SFTP connection that should be fixed to an
exact implementation of the SFTP server to not to be routed to a fake server
one day."
_cerror += " Therefore you have to add a 'fingerprint' in the
connection parameters."
_cerror += crlf+"Please add the following text under 'Additional
connection parameters' and try again:"
_cerror += crlf+crlf+'-hostkey="'+a[1]+'"'+crlf+crlf
endif
endif
self:seterror(_cerror)
return false
elseif ccommand == "DIRECTORY"
a := StringExtract2Array(c, "<file>", "</file>", "")
for i := 1 upto ALen(a)
afile := StringExtract2Array(a[i], '="', '" />', "")
if ALen(afile) >= 4
if afile[2] =="-"
ct := afile[4]
d := MakeDate(SubStr(ct, 1, 4), SubStr(ct, 9, 2), SubStr(ct, 6,
2))
ct := SubStr(ct, 12, 8)
AAdd(_aresult,{afile[1], Val(afile[3]), d, ct, ""})
elseif afile[2] =="D"
if !(afile[1] == "..")
ct := afile[4]
d := MakeDate(SubStr(ct, 1, 4), SubStr(ct, 9, 2), SubStr(ct,
6, 2))
ct := SubStr(ct, 12, 8)
AAdd(_aresult,{afile[1], 0, d, ct, "D"})
endif
endif
endif
next
elseif InList (ccommand, "GETFILE", "PUTFILE")
if !Instr('result success="true"', c)
self:seterror ("Missing transfer result text "+ crlf+c)
endif
else
// NOP
endif
return true
method seterror (cerror as string) as void pascal class clsFTPWinSCP
_cerror := cerror
_nerror := 98765
return
method AddDirstack () as void pascal class clsFTPWinSCP
local i as dword
_laddcommandsbefore := true
for i := ALen(_adirstack) downto 1
self:SetCurDirInternal(_adirstack[i])
next
_laddcommandsbefore := false
return
method AddOpen() as void pascal class clsFTPWinSCP
// Beispiel open ftp://Reseller:KgT66mW3@ftp.acs.it
local c as string
c := ""
c += "option batch abort" +crlf
c += "option confirm off" +crlf
c += "open "
if _cmode == "FTPWSCP"
c += "ftp://"
elseif _cmode == "SFTPWSCP"
c += "sftp://"
elseif _cmode == "FTPSWSCP"
c += "ftps://"
else
self:seterror ("Not allowed parameter (cmode) " + _cmode)
return
endif
c += _cuser
c += ":"
c += _cpassword
c += "@"
c += _cftp
if !Empty(_nport)
c += ":"+NTrim(_nport)
endif
c += "/"
if !Empty(_cparams)
c += " "+_cparams
endif
c += crlf
_laddcommandsbefore := true
self:AddCommand(c)
_laddcommandsbefore := false
return
method PostExecute() as void pascal class clsFTPWinSCP
local i as dword
local cdir as string
_ccommands := ""
for i := 1 upto ALen(_adirstackNew)
cdir := _adirstackNew[i]
// Doppeltes zurück fehlt noch
if cdir == ".." .and. alen(_adirstack) >= 1 .and.
!(_adirstack[alen(_adirstack)]== "..")
AAUS (_adirstack,ALen(_adirstack))
else
AAdd (_adirstack, cdir)
endif
next
_adirstackNew := {}
self:__DeleteTempfiles()
return
method SetCurDirInternal (cRemoteDir as string) as logic pascal class
clsFTPWinSCP
// Darf nicht aufgerufen werden von außen!
self:AddCommand('cd "'+cRemoteDir+'"')
return self:CheckExecute("SetCurDir")
method CloseRemote () class clsFTPWinSCP
local lok as logic
lok := true
if !Empty(_ccommands)
lok := false
self:seterror ("Not all commands executed")
endif
return lok
method CheckExecutedAll() class clsFTPWinSCP
return self:CheckExecute("ALL")
assign lSafeFTPFileTransfer (l as logic) as void pascal class clsFTPWinSCP
if !l
if _cPutmode == "RENAME"
_cPutmode := "NONE"
endif
endif
return
method __Createtempfile(cTempFile as string) as void pascal class
clsFTPWinSCP
if !ffilewrite (ctempfile, getserverdatetime(5))
self:seterror ("TempFile Creation")
endif
AAdd (_adeletetempfiles, cTempFile)
return
method __DeleteTempfiles() as void pascal class clsFTPWinSCP
local i as dword
for i := 1 upto ALen(_adeletetempfiles)
FDeleteFile (_adeletetempfiles[i], true)
next
_adeletetempfiles := {}
return
method __GetVersion() class clsFTPWinSCP
return " Todo 91901 AO 2015-06-05 18:11 Vulcan, Ersatz ACSINET"
Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Secure FTP or SFTP support in VO "Dirk (Belgium)" <dirk.dot.herijgers@pbprojects.dot.be> - 2015-07-24 06:23 +0000
Re: Secure FTP or SFTP support in VO "Wolfgang Riedmann" <wriedmann@gmail.com> - 2015-07-24 09:14 +0200
Re: Secure FTP or SFTP support in VO "Dirk (Belgium)" <dirk.dot.herijgers@pbprojects.dot.be> - 2015-07-27 06:25 +0000
Re: Secure FTP or SFTP support in VO "Philippe Bayard (Belgium)" <philbayard@gmail.com> - 2015-07-28 03:35 -0700
Re: Secure FTP or SFTP support in VO "Marc Verkade [MITCon]" <marc@mitNOSPAMconDELETE.nl> - 2015-07-28 18:16 +0200
Re: Secure FTP or SFTP support in VO "Dirk (Belgium)" <dirk.dot.herijgers@pbprojects.dot.be> - 2015-07-29 07:27 +0000
Re: Secure FTP or SFTP support in VO "Philippe Bayard (Belgium)" <philbayard@gmail.com> - 2015-07-29 02:10 -0700
Re: Secure FTP or SFTP support in VO "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it> - 2015-07-29 16:42 +0200
Re: Secure FTP or SFTP support in VO "Marc Verkade [MITCon]" <marc@mitNOSPAMconDELETE.nl> - 2015-08-04 07:01 +0200
Re: Secure FTP or SFTP support in VO "Dirk (Belgium)" <dirk.dot.herijgers@pbprojects.dot.be> - 2015-08-04 07:12 +0000
csiph-web