Please uses the wwSftpClient Class instead.
This class provides an SFTP client that works with SSH based secure FTP connections. This is the most common secure FTP format used for *nix based servers and most widely supported.
Does not support FTPS
SFTP and FTPS are two completely separate protocols and this library only supports SSH based SFTP, not FTPS which is FTP over TLS.
This class is based on wwFtp and supports the same interface for the most part - there are subtle differences in how directory listings are handled (you should only pass in paths, not wildcards which are invalid for the SSH client). Like wwFtp this class supports both high level and lower level routines for sending files.
There are two types of operations:
High Level Self-Contained Operations
SpecificallyFtpGetFile()
andFtpSendFile()
which open a connection and send/receive a file, then close the connection. They are self-contained and don't require an explicit call to open and close connections.Low Level Operations - Require an Open Connection
All other operations are connection based, meaning they require that a connection created withFtpConnect()
is open before you call the low level operations. You can run multiple low level operations on the same open connection.
High Level Upload and Download
The High level functions are easy functions to upload and download files FtpGetFile()
and FtpSendFile()
as they are single commands that don't require explicitly opening and closing of connections.
loFtp = CREATEOBJECT("wwSftp")
loFtp.nFtpPort = 23
lcHost = "127.0.0.1"
lnPort = 23
lcUsername = "tester"
lcPassword = "password"
*** Download
lcOutputFile = ".\tests\sailbig.jpg"
DELETE FILE lcOutputFile
lnResult = loFtp.FtpGetFile(lcHost,"sailbig.jpg",".\tests\sailbig.jpg",1,lcUsername,lcPassword)
this.AssertTrue(lnResult == 0,loFtp.cErrorMsg)
this.AssertTrue(FILE(lcOutputFile))
*** Upload a file
lcSourceFile = ".\tests\sailbig.jpg"
lcTargetFile = "Sailbig2.jpg"
lnResult = loFtp.FtpSendFile(lcHost,lcSourceFile,lcTargetFile,lcUsername,lcPassword)
this.AssertTrue(lnResult == 0,loFtp.cErrorMsg)
Low Level Functions
The lower level functions require that you set properties on the wwSFTP object, create a connection and then use the individual methods to send and receive files, list and change directories, delete files, create folders etc. The advantage of this mechanism is that you have more control over the process as well as keeping a connection open between requests which is more efficient for sending multiple files.
The following is an integration test that demonstrates a host of the lower level features:
loFtp = CREATEOBJECT("wwSftp")
loFtp.cFtpServer = "127.0.0.1"
loFtp.nFtpPort = 23
loFtp.cUsername = "tester"
loFtp.cPassword = "password"
loFtp.FtpConnect()
*** Change to a specific folder - convenience only - you can reference relative paths
this.AssertTrue(loFtp.FtpSetDirectory("subfolder"),loFtp.cErrorMsg)
*** Create a new directory
this.AssertTrue(loFtp.FtpCreateDirectory("SubFolder2"),loFtp.cErrorMsg)
*** Send a file into the new directory
this.AssertTrue(loFtp.FtpSendFileEx(".\tests\sailbig.jpg","subfolder2/sailbig.jpg")==0,loFtp.cErrorMsg)
*** Download the file just uploaded
this.AssertTrue(loFtp.FtpGetFileEx("subfolder2/sailbig.jpg",".\tests\sailbig2.jpg")==0,loFtp.cErrorMsg)
*** Delete it
this.AssertTrue(loFtp.FtpDeleteFile("subfolder2/sailbig.jpg")==0,loFtp.cErrorMsg)
*** And delete the folder
this.AssertTrue(loFtp.FtpRemoveDirectory("Subfolder2"),loFtp.cErrorMsg)
Remarks
Dependencies
- .NET 4.5 or later
- wwDotnetBridge.dll
- renci.ssh.dll
Class Members
Member | Description | |
---|---|---|
OnFtpBufferUpdate |
This event handler can be used to provide progress information and cancel long running downloads or uploads. | |
FtpClose |
Closes the FTP Connection. o.FtpClose() |
|
FtpConnect |
Opens a connection to the server. Actually it doesn't open the connection, but it sets up the connection properties. Actual connection occurs when a send or receive operation on the FTP connection. o.FtpConnect(lcServer, lcUsername, lcPassword) |
|
FtpCreateDirectory |
Creates a directory on the server. o.FtpCreateDirectory(lcPath) |
|
FtpDeleteFile |
Deletes a file on the FTP server. o.FtpDeleteFile(lcFile) |
|
FtpGetFile |
High level function to download a file from the SFTP server. o.FtpGetFile(lcFTPServer, lcFtpSource, lcLocalTarget, lnBinary, lcUsername, lcPassword) |
|
FtpGetFileEx |
Downloads a file from the Ftp server to a local folder. Make sure to call FtpConnect() before calling this method.o.FtpGetFileEx(lcFtpSourceFile, lcLocalTargetFile) |
|
FtpListFiles |
Gets a file listing for a remote folder and returns a collection of objects with the following properties: o.FtpListFiles(lcPath) |
|
FtpRemoveDirectory |
Removes a directory from the FTP server. o.FtpRemoveDirectory(lcPath) |
|
FtpRenameFile |
Renames a file on the server without deleting and reuploading. o.FtpRenameFile(lcOldname, lcNewName) |
|
FtpSendFile |
Single method call to send a file to the FTP server. o.FtpSendFile(lcFTPServer, lcSource, lcTarget, lcUsername, lcPassword) |
|
FtpSendFileEx |
Sends a file to the server on an already open connection. Make sure you have called FtpOpenConnection() before calling this method.o.FtpSendFileEx(lcLocalSourceFile, lcFtpTargetFile) |
|
FtpSetDirectory |
Changes the active server path to the specified folder. o.FtpSetDirectory(lcNewPath) |
|
Init |
Stock Properties o.Init() |
|
Load |
Load o.Load() |
|
cFtpServer |
Specifies the FTP Server to connect to. | |
cPassword |
||
cPrivateKeyFile |
An optional private key file to pass instead of or in addition to a password. Path should be fully qualified. | |
cPrivateKeyFilePassword |
An optional password for a keyfile if provided in the cPrivateKeyFile property. | |
cUsername |
||
nFtpPort |
Specifies the FTP port to connect to on the server. | |
oSFTP |
Instance of the SftpFtpCLient .NET wrapper class. |
|
oSFTPClient |
Instance of the SSH.NET SftpClient object. Accessible here to allow additional configuration options. |
Requirements
Assembly: wwsftp.prg© West Wind Technologies, 2024 • Updated: 05/26/24
Comment or report problem with topic