SFTP from c# or VB.NET

We are currently evaluating the SmartFTP Library and are havign a little difficulty in establishing a connection to a Secure Server. When we use the SmartFTP Client software we have no issues but from .NET code we cannot establish a connection. I have attached the relevant code sample here (in VB.NET sorry, but its close enough to c#). Can someone tell us what we are doing wrong when we call 'EstablishConnection' ?

Thanks in advance.
Syd.

VB CLASS LISTING

Imports sfFTPLib

Public Class FTPServices

Dim strUsername As String
Dim strPassword As String
Dim strServer As String

Public objFTP As New sfFTPLib.SFTPConnection

Public Function EstablishConnection() As Boolean
' ---------------------------------------------------------------------------------
' Function - FTPServices.EstablishConnection
' Written by - Syd O
' Created on - 27 May '08
' Last Update -
' Function Purpose - To establish connection to FTP Server Securely
' ---------------------------------------------------------------------------------

If CheckLicence() Then ' Currently a Stub for testing & evaluation. ALWAY WILL RETURN TRUE

' note Server is Gene6 FTP and is configured to accept Explicit SSL on port 21
' The server operates with SmartFTP client and has no issues we are aware of

strServer = "192.168.1.114" ' Only For Testing

objFTP.Host = strServer
objFTP.Port = 21
objFTP.Username = strUsername
objFTP.Password = strPassword
objFTP.ClientHostname = System.Environment.MachineName
objFTP.Proxy.Type = enumProxyType.ftpProxyTypeNone
objFTP.Client = "VBExpress"
objFTP.LogFile = System.Environment.MachineName + ".log"

Select Case objFTP.Connect()

Case enumError.ftpErrorSuccess
MsgBox("Connected")

Case Else
MsgBox(enumError.ftpErrorConnect.ToString)

End Select

End If

End Function

The default SFTP port is 22 not 21

So
Wrong: objFTP.Port = 21
Right: objFTP.Port = 22

Regards,
Mat

The default SFTP port is 22 not 21
So
Wrong: objFTP.Port = 21
Right: objFTP.Port = 22

Regards,
Mat

Thanks, but we have set up the server to accept on Port 21 and it does so fine from the regular Smart FTP Client.

We have tried as you suggested using port 22 (the server is also set up for this) but it still fails yet the server works with the regular SmartFTP Client with this configuration. We get an error 25 - ErrorConnect.

In summary, we do not think it is likely that this is a Server issue as we can connect with Smart & other FTP client software to the Server in the same configuration, more likely is our complete misunderstanding of how to implement the sfFTPLib library correctly. Perhaps someone has done this before and is willing to share the code with us?

Please post the log from SmartFTP showing a successful connection to the server.

And also post the log from the SFTPConnection. Its the file you specify in the LogFile property.

Thanks, but we have set up the server to accept on Port 21 and it does so fine from the regular Smart FTP Client.

We have tried as you suggested using port 22 (the server is also set up for this) but it still fails yet the server works with the regular SmartFTP Client with this configuration. We get an error 25 - ErrorConnect.

In summary, we do not think it is likely that this is a Server issue as we can connect with Smart & other FTP client software to the Server in the same configuration, more likely is our complete misunderstanding of how to implement the sfFTPLib library correctly. Perhaps someone has done this before and is willing to share the code with us?
[codebox][20080602 08:36:13] SmartFTP FTP Library v1.5.13.28
[20080602 08:36:13] Resolving host name "192.168.1.114"
[20080602 08:36:13] Connecting to 192.168.1.114 Port: 21
[20080602 08:36:13] Incompatible SSH server running on host.
[20080602 08:36:13] Client closed the connection.
[20080602 08:36:13] 2
[20080602 08:36:33] SmartFTP FTP Library v1.5.13.28
[20080602 08:36:33] Resolving host name "192.168.1.114"
[20080602 08:36:33] Connecting to 192.168.1.114 Port: 22
[20080602 08:36:33] Incompatible SSH server running on host.
[20080602 08:36:33] Client closed the connection.
[20080602 08:36:33] 2
[/codebox]

I notice the line "Incompatible SSH Server running on host." Why then does the SmartFTP client work but the Library not?

Please post the log from SmartFTP as well.

Please post the log from SmartFTP as well.
[codebox][10:55:30] SmartFTP v3.0.1016.15
[10:55:31] Resolving host name "192.168.1.114"
[10:55:31] Connecting to 192.168.1.114 Port: 22
[10:55:31] Connected to 192.168.1.114.
[10:55:31] 220 Gene6 FTP Server v3.10.0 (Build 2) ready...
[10:55:31] AUTH TLS
[10:55:31] 234 AUTH command ok; starting SSL connection.
[10:55:31] Connected. Exchanging encryption keys...
[10:55:31] Session Cipher: 128 bit RC4
[10:55:32] TLS encrypted session established.
[10:55:32] PBSZ 0
[10:55:32] 200 PBSZ=0
[10:55:32] USER VBExpress
[10:55:32] 331 Password required for VBExpress.
[10:55:32] PASS (hidden)
[10:55:32] 230 User VBExpress logged in.
[10:55:32] SYST
[10:55:32] 215 UNIX Type: L8
[10:55:32] Detected Server Type: UNIX
[10:55:32] FEAT
[10:55:32] 211-Extensions supported:
[10:55:32] AUTH TLS
[10:55:32] CCC
[10:55:32] CLNT
[10:55:32] CPSV
[10:55:32] EPRT
[10:55:32] EPSV
[10:55:32] MDTM
[10:55:32] MFCT
[10:55:32] MFMT
[10:55:32] MLST type*;size*;create;modify*;
[10:55:32] MODE Z
[10:55:32] PASV
[10:55:32] PBSZ
[10:55:32] PROT
[10:55:32] REST STREAM
[10:55:32] SIZE
[10:55:32] SSCN
[10:55:32] TVFS
[10:55:32] UTF8
[10:55:32] XCRC "filename" SP EP
[10:55:32] XMD5 "filename" SP EP
[10:55:32] XSHA1 "filename" SP EP
[10:55:32] 211 End.
[10:55:32] CLNT SmartFTP 3.0.1016.15
[10:55:32] 200 Noted.
[10:55:32] Detected Server Software: Gene6 FTP Server 3.x
[10:55:32] OPTS UTF8 ON
[10:55:32] 200 UTF8 OPTS ON
[10:55:32] PWD
[10:55:32] 257 "/" is current directory.
[10:55:33] TYPE A
[10:55:33] 200 Type set to A.
[10:55:33] PROT P
[10:55:33] 200 PROT command successful.
[10:55:33] PASV
[10:55:33] 227 Entering Passive Mode (192,168,1,114,197,131)
[10:55:33] Opening data connection to 192.168.1.114 Port: 50563
[10:55:33] MLSD
[10:55:33] Connected. Exchanging encryption keys...
[10:55:33] 150 Data connection accepted from 192.168.1.207:2876; transfer starting.
[10:55:33] Session Cipher: 128 bit RC4
[10:55:33] TLS encrypted session established.
[10:55:33] 1855 bytes transferred. (8.92 KB/s) (203 ms)
[10:55:33] 226 Transfer ok.
[10:56:04] NOOP
[10:56:04] 200 NOOP command successful.
[/codebox]

Hello ..

You are connecting to the server using FTP over SSL/TLS with SmartFTP and not with SFTP over SSH. To correct the problem in your code use the FTPConnection class and not the SFTPConnection class. Better try to look at the sample in the Samples\FTP\VB.NET\ folder.

Dim objFTP As sfFTPLib.FTPConnectionMTAClass

'objFTP = CreateObject("sfFTPLib.FTPConnectionMTA")
objFTP = New sfFTPLib.FTPConnectionMTA

' Favorite settings
objFTP.Host = "192.168.1.114"
objFTP.Port = 22
objFTP.Protocol = sfFTPLib.enumProtocol.ftpProtocolSSLExplicit
objFTP.Username = "VBExpress"
objFTP.Password = "password"
objFTP.MLST = True
objFTP.Passive = True

Regards,
Mat

Hello ..

You are connecting to the server using FTP over SSL/TLS with SmartFTP and not with SFTP over SSH. To correct the problem in your code use the FTPConnection class and not the SFTPConnection class. Better try to look at the sample in the Samples\FTP\VB.NET\ folder.

Dim objFTP As sfFTPLib.FTPConnectionMTAClass

'objFTP = CreateObject("sfFTPLib.FTPConnectionMTA")
objFTP = New sfFTPLib.FTPConnectionMTA

' Favorite settings
objFTP.Host = "192.168.1.114"
objFTP.Port = 22
objFTP.Protocol = sfFTPLib.enumProtocol.ftpProtocolSSLExplicit
objFTP.Username = "VBExpress"
objFTP.Password = "password"
objFTP.MLST = True
objFTP.Passive = True

Regards,
Mat

Thanks for your help, but as we understand this the only way we can use ModeZ is with SSL/TLS so we are a little confused here. Can you provide a guiding light?

Kind regards,

Thanks for your help, but we need to use the SFTPConnection Class as it exposes ZLIB. As we understand this the only way we can use ModeZ is with SSL/TLS so we are a little confused here. Can you provide a guiding light?

Kind regards,

Hello ..

The FTPConnectionMTA class offers SSL/TLS with MODE Z support. What you are looking for is FTPCoonnectionMTA and not the SFTPConnection class.

Regards,
Mat

Hello ..

The FTPConnectionMTA class offers SSL/TLS with MODE Z support. What you are looking for is FTPCoonnectionMTA and not the SFTPConnection class.

Regards,
Mat
Thanks Issue Resolved. Best Support I've experienced in a long while.