edtFTPnet/PRO now supports the use of SCP to transfer files to and from SCP servers.
IMPORTANT: An SCP compatible server is required for this example. You can download a free trial of CompleteFTP, a Windows SCP server (that also supports SFTP, FTPS and other protocols), from this link. Choose the Professional Edition when installing.
SCP works over the SSH protocol, just as SFTP does, so details about client and server validation for SFTP are also applicable to SCP. See How to use SFTP (introduction) and subsequent SFTP topics on server and client validation.
The SCP protocol does not support resumption of transfers or ASCII mode transfers, and so these features are not supported. Recursive transfers are not currently supported by edtFTPnet/PRO, but may be in a future release.
Code to perform an upload and download via SCP is shown below. A remote SSH command is used to delete the file on the server.
SecureFTPConnection ftpConnection = new SecureFTPConnection();
// set the host address and credentials
ftpConnection.ServerAddress = "localhost";
ftpConnection.UserName = "javaftp";
ftpConnection.Password = "javaftp";
// set the protocol to SCP
ftpConnection.Protocol = FileTransferProtocol.SCP;
// connect and change to the correct directory
ftpConnection.Connect();
ftpConnection.ChangeworkingDirectory("/home/javaftp/remote/test");
// upload a byte array to a file
byte[] file = Encoding.ASCII.GetBytes("this is a test");
ftpConnection.UploadByteArray(file, "test.txt");
// download the file
ftpConnection.DownloadFile("C:\\temp\\test.txt", "test.txt");
// delete the file on the server. Since we can't do this via SCP, we issue a remote command
ftpConnection.InvokeCommandSSH("rm test.txt");
ftpConnection.Close();
By default, server validation is switched off. For a production application, it should be switched on - see How to use SFTP (with server validation) for more details.