Conect to SFTP Server

Hello Support

I am trying to connect to sftp server, but with no result. I was using 4d ftp login command, but it only work for FTP. How did i connect using ssh or sftp??

4D Internet Commands does not support SFTP or FTPS.

For now, you could use:

During the Summit presentation, it was implied that 4D Internet Commands will be phased out, replaced by native commands. Hopefully the options above will only be necessary for a short period of time.

Another option, if you’re using WIndows, is WinSCP called via LEP. I’ve been using it for a quite a while and it works very well.

I assume there’s an equivalent to WinSCP for Mac.

1 Like

There is an sftp command line program preinstalled.

Preinstalled with what? Windows?

Sorry, I should have specified; Mac.

Aha. Lucky Mac uses. :wink:

I think I missed that one… Can you refresh on which one it was ? Thanks Miyako :slight_smile:

Now that you say it, I think it might have been removed in the final cut…

Hi Miyako,

You have now officially “leaked” that information :wink:

Thanks Miyako :pray:

I thought it is obvious…
4D IC has a couple of different areas.
SMTP Send: deprecated with v18
POP3 receive: deprecated with v18 R3
IMAP receive: deprecated with v18 Rx (big topic, will take several Releases)

When IMAP is finished, depending on customer feedback, File Transfer could be next to start…
File Transfer is of course no longer FTP. SFTP? Or not better FTPS, which would be very easy to handle for the admin (same certificate as for HTTP, same way to use it) or as asked here SFTP.
With FTPS we would get not only encryption but also better trust level (who is the other side…)

1 Like

Hi Thomas.

I know it is obvious and logical but it was not official. Now it is :slight_smile:

What about JMAP, are there plans for it? I know it is rather new, but is very promising.

Yes, we love it.
When you take a look on the object used for the new POP3 or SMTP commands you will (or might) notice that this is extremely close to JMAP, because that’s what we use internally, and then convert to “classic protocol”. Object to MIME, MIME to object… (=object? read JMAP)

It is not really new. But there is still nearly no usage outside, I mean no big player, no ISV, close to nobody is providing a JMAP access, no, at this point, there is no plan to use it for communication.

Hi Thomas,

FTP and FTPS are the two that I use the most. Besides that, the low level TCP and UDP commands are very important to me.


1 Like

Hello Peter,

Would you be prepared to share some code that does this (WinSCP called via LEP)?


Hi David,

Here ya go. I haven’t tested this. I’ve taken my code and stripped out all calls to all sorts of helper methods of mine which handle error checking a file path building etc. I’ve replaced some of them with simple native 4D code to try an make it obvious what it is supposed to do. Hopefully it makes sense.

$o_Options contains a few properties which you should be able to infer from the code.

I hope it helps.




$d_Date:=Current date
$t_LogFolderPath:=Get 4D folder(Logs folder)+"SFTP Logs"+Folder separator
$t_LogFilePath:=$t_LogFolderPath+String(Year of($d_Date);"0000")+" "+String(Month of($d_Date);"00")+" "+String(Day of($d_Date);"00")+".log"

$t_TempFolderPath:=Temporary folder+"SFTP"+Folder separator

$t_ScriptData:="open sftp://"+$o_Options.UserName+"@"+$o_Options.HostAddress+"/"\
+" -hostkey="+kSM+$o_Options.HostKey+kSM\
+" -privatekey="+kSM+$o_Options.PrivateKeyFilePath+kSM\
+" -rawsettings FSProtocol=2"+kCRLF

Case of 
	: ($o_Options.Action="LS")
		$t_ScriptData:=$t_ScriptData+"cd /"+String($o_Options.RemoteDirectory)+kCRLF
	: ($o_Options.Action="GET")
		$t_ScriptData:=$t_ScriptData+"get "+kSM+"/"+String($o_Options.RemoteFilePath)+kSM+" "+kSM+$o_Options.LocalFilePath+kSM+kCRLF
	: ($o_Options.Action="PUT")
		$t_ScriptData:=$t_ScriptData+"put "+kSM+$o_Options.LocalFilePath+kSM+" "+kSM+"/"+String($o_Options.RemoteFilePath)+kSM+kCRLF
	: ($o_Options.Action="RM")
		$t_ScriptData:=$t_ScriptData+"rm "+kSM+"/"+String($o_Options.RemoteFilePath)+kSM+kCRLF
End case 



+" /log="+kSM+$t_LogFilePath+kSM\
+" /xmllog="+kSM+$t_XMLLogFilePath+kSM\
+" /ini=nul"\
+" /script="+kSM+$t_ScriptFilePath+kSM+kCRLF
$t_BatchData:=$t_BatchData+"ECHO All done > "+kSM+$t_FlagFilePath+kSM+kCRLF  //Create a flag file to tell 4D the .bat file is finished

TEXT TO DOCUMENT($t_ScriptFilePath;$t_ScriptData;"ISO-8859-1")
TEXT TO DOCUMENT($t_BatchFilePath;$t_BatchData;"ISO-8859-1")


LAUNCH EXTERNAL PROCESS("cmd.exe /C start \"\" \""+$t_BatchFilePath+"\"")

DOC Wait Until File Exists ($t_FlagFilePath)  //Loops checking for the exisitence of $t_FlagFilePath


Case of 
	: (Test path name($t_FlagFilePath)#Is a document)
		$o_Options.ErrorMessage:="Timed Out waiting for a Response from the Remote SFTP Server"
	: (Test path name($t_XMLLogFilePath)#Is a document)
		$o_Options.ErrorMessage:="No Output data returned from the Remote SFTP Server.  The XML Log File was not created"
		$t_Data:=Document to text($t_XMLLogFilePath)
End case 

DELETE DOCUMENT($t_ScriptFilePath)


Thank you so much Peter.
By the way is there a place on this new forum which allows private emails? A thank you note like this does not need to be seen by all nor kept for posterity.

Yes you can DM somebody. Click on the person name and then on “Message” :wink:

1 Like