Question
· Oct 25, 2021

Problem with sftp

Hello, everyone,

I have the problem that when trying to connect to the SFTP server the error appears, the user and password are wrong. However, these are correctly stored under login data and I entered! SFTP in SSL Config. The connection works wonderfully with Filezilla. Anyone else has a tip for me?

greeting

Discussion (2)2
Log in or sign up to continue

Port no is 22 for sftp

below is my code

ClassMethod ConnectSFTP(TargetServer As %String, Username As %String, Password As %String, TargetFolder As %String, FilePath As %String, PortNo As %Integer) As %String
{
set pcs=$l(FilePath,"\"),FileName=$p(FilePath,"\",pcs)
set stream=##class(%Stream.FileBinary).%New()
set From = ##class(%File).%New(FilePath),sc=From.Open("RU")
  set sc=stream.CopyFrom(From)
;--------------------
set ssh=##class(%Net.SSH.Session).%New(),sftp=""
set Status1=ssh.Connect(TargetServer) if Status1'=1 quit "No Connection"
set Status2=ssh.AuthenticateWithUsername(Username,Password) if Status2'=1 quit "Not Authenticated"
set Status3=ssh.OpenSFTP(.sftp) if sftp="" quit "Failed to create the sftp object"
set Target=TargetFolder_"/"_FileName
set Status4=sftp.PutStream(stream,Target,,0) ; 0777=everybody
if Status4'=1 do  quit "Failed to Transfer file"
.set NO=$i(^abcErrorTrap(0)),^abcErrorTrap(NO,1)=Status4,^abcErrorTrap(NO,2)="SFTP"
.set ^abcErrorTrap(NO,3)=Target
.set ^abcErrorTrap(NO,4)=FilePath
.set ^abcErrorTrap(NO)=$zt($p($h,",",2),2)
set Status5=sftp.%OnClose()
kill sftp,stream,From,ssh
quit "Successful"
}