Using Ultimate FTP & SFTP Libraries to Transfer Files Between FTP & SFTP Servers
To upload a file from other file system to an FTP file system (in Ultimate FTP Library), simply use the CopyFrom methods.
The following example demonstrates how to connect to FTP and SFTP servers, and use the CopyFrom method to directly copy a file from the SFTP file system to the FTP file system. If you need to upload files and directories within a ZIP file to the SFTP server, see the topic Uploading files and directories within a ZIP file to an FTP server.
Remember to add using directives to your code to create aliases for existing namespaces and avoid having to type the fully qualified type names. The namespaces are ComponentSoft.Net and ComponentSoft.IO.
The following example demonstrates copying files from an SFTP server to an FTP server without creating temporary files on the local PC.
Before using the component, please add references to assemblies in the picture below:
Using Ultimate SFTP and FTP components to transfer a file
| C# | |
|---|---|
|
// Connect to an FTP file system.
Ftp ftpsys = new Ftp(); ftpsys.Connect("192.168.126.128", 21); ftpsys.Authenticate("test", "test"); // Connect to an SFTP file system. Sftp sftp = new Sftp(); sftp.Connect("192.168.126.128", 2222); sftp.Authenticate("test", "test"); // Copy 'blog.txt' file from the SFTP file system to the FTP file system. ftpsys.CopyFrom(sftp, "blog.txt", "my blog on FTP file system.txt"); ftpsys.Disconnect(); sftp.Disconnect(); |
|
| VB.NET | |
|---|---|
|
' Connect to an FTP file system.
Dim ftpsys As New Ftp() ftpsys.Connect("192.168.126.128", 21) ftpsys.Authenticate("test", "test") ' Connect to an SFTP file system. Dim sftp As New Sftp() sftp.Connect("192.168.126.128", 2222) sftp.Authenticate("test", "test") ' Copy 'blog.txt' file from the SFTP file system to the FTP file system. ftpsys.CopyFrom(sftp, "blog.txt", "my blog on FTP file system.txt") ftpsys.Disconnect() sftp.Disconnect() |
|
The CopyFrom method of the FileSystem class queries information for the source file, creates a new file for writing on the destination file system and initiate the data transfer between the source file system and the destination file system.
If you need to upload selected files to an SFTP server, please see Uploading selected files using Ultimate SFTP topic.
The component can be downloaded at this web page. For moe information about the component, please see this post and this web page.