AW: SFTP

Rudolf Bargholz rudolf at bargholz.ch
Fri Jun 3 05:50:14 EDT 2016


Hi Jacques,

We script this using WinSCP, call the WinSCP standalone EXE from Omnis Studio.

Regards

Rudolf

;  "C:\olt\tools\winscp\winscp.bat" "C:\olt\tools\winscp\WinSCP.exe" "C:\Users\adm_rb\Desktop\winscp.xml" "option batch abort" "option confirm off" "open ftp://oltzrh:qm8t0k2z@montreal.onlinetravel.ch" "/winscp" "C:\Users\adm_rb\Desktop\te st.txt"

If FlagOk
Do FileOps.$splitpathname(sys(10),Drive,Directory,FileName,FileExtension)
Calculate WinScpExeFullPath as trim(con(Drive,Directory),0,1,sys(9))
Calculate WinScpExeFullPath as con(WinScpExeFullPath,sys(9),'tools',sys(9),'winscp',sys(9),'winscp.exe')
If not(FileOps.$doesfileexist(WinScpExeFullPath))
Calculate pErrmess as con('oNotWinScpFtp.$sendFtp WinSCP.exe path does not exist: "',WinScpExeFullPath,'"',kCr,kLf,pErrmess)
Calculate FlagOk as kFalse
End If
End If

If FlagOk
Do $cinst.$_createObject(BatchFileOpsObj,'ONLINE','oFileOps') Returns FlagOk
If FlagOk
If low(iTransferType)='binary'
Calculate BatchFileContents as '"%1" /xmllog="%2" /command "option batch abort" "option confirm off" "option transfer binary" "open "%3"" "cd "%4"" "put "%5"" "close" "exit"'
Else
Calculate BatchFileContents as '"%1" /xmllog="%2" /command "option batch abort" "option confirm off" "option transfer ascii" "open "%3"" "cd "%4"" "put "%5"" "close" "exit"'
End If
Do BatchFileOpsObj.$tmpFileObjRefCreate('winscpbatch','bat',BatchFileContents) Returns FlagOk
If FlagOk
Calculate BatchFileFullPath as BatchFileOpsObj.$reflectFullFilePath()
Do BatchFileOpsObj.$closefile()
End If
End If
End If

If FlagOk
Do $cinst.$_createObject(LogFileOpsObj,'ONLINE','oFileOps') Returns FlagOk
If FlagOk
Do LogFileOpsObj.$tmpFileObjRefCreate('winscplog','xml','') Returns FlagOk
If FlagOk
Calculate LogFileFullPath as LogFileOpsObj.$reflectFullFilePath()
Do LogFileOpsObj.$closefile()
End If
End If
End If

If FlagOk

;  open sftp://martin:mypassword@example.com -hostkey="ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
;  open scp://test@example.com:2222 -privatekey=mykey.ppk
;  open ftps://martin@example.com -implicit -certificate="xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
;  open martin at example.com
;  open example.com
;  open

Switch low(pType)
Case 'sftp'
Calculate FtpOpenString as 'sftp'
Calculate iFtpPort as pick(isnull(iFtpPort),iFtpPort,0)
If iFtpPort=0
Calculate iFtpPort as 22
End If
If iFtpPort=21
Calculate iFtpPort as 22
End If
Default
Calculate FtpOpenString as 'ftp'
Calculate iFtpPort as pick(isnull(iFtpPort),iFtpPort,0)
If iFtpPort=0
Calculate iFtpPort as 21
End If
End Switch

If pos(' ',iFtpHost)=0
Calculate lFtpPortString as con(':',iFtpPort)
End If
Calculate FtpOpenString as con(FtpOpenString,'://',iFtpUsername,':',iFtpPassword,'@',iFtpHost,lFtpPortString)

End If

If FlagOk

Begin text block
Text: "[BatchFileFullPath]" "[WinScpExeFullPath]" "[LogFileFullPath]" "[FtpOpenString]" "[iFtpInitDir]" "[iDocumentFullPath]"
End text block
Get text block BatchFileLaunchString

Launch program [BatchFileLaunchString] Returns FtpResponse (Do not quit Omnis)

End If

If FlagOk
If not(FileOps.$doesfileexist(LogFileFullPath))
Calculate FlagOk as kFalse
End If
End If

If FlagOk
If not(LogFileOpsObj.$openfile(LogFileFullPath))
Calculate FlagOk as kFalse
Calculate pErrmess as con('oNotWinScpFtp.$sendFtp unable to open ftp log file.',kCr,kLf,pErrmess)
Else
Do LogFileOpsObj.$readfile(lFtpLogFileContents)
Do LogFileOpsObj.$closefile()
End If
End If

If FlagOk
If len(lFtpLogFileContents)=0
Calculate FlagOk as kFalse
Calculate pErrmess as con('oNotWinScpFtp.$sendFtp empty ftp log file.',kCr,kLf,pErrmess)
End If
End If

If FlagOk
If pos('result success="true"',lFtpLogFileContents)=0
Calculate FlagOk as kFalse
Calculate pErrmess as con('oNotWinScpFtp.$sendFtp upload error.',kCr,kLf,lFtpLogFileContents,kCr,kLf,pErrmess)
End If
End If

Quit method FlagOk

-----Ursprüngliche Nachricht-----
Von: omnisdev-en [mailto:omnisdev-en-bounces at lists.omnis-dev.com] Im Auftrag von Jacques Zemron
Gesendet: Freitag, 3. Juni 2016 11:00
An: OmnisDev List - English <omnisdev-en at lists.omnis-dev.com>
Betreff: SFTP

Hi all,

I want to do SFTP transfert with Studio 6. Is it possible ?

Cordialement,

Jacques ZEMRON
 


2, Impasse du Marechal Ferrant
14540 SOLIERS
Tel : 02 31 72 73 54
Fax : 02 31 26 94 72
Portable : 06 82 68 60 08
Mailto:jacky at aec-ri.com





_____________________________________________________________
Manage your list subscriptions at http://lists.omnis-dev.com




More information about the omnisdev-en mailing list