Upload file using FTP
First you need to add reference to Ftp.dll .NET FTP library, and import appropriate namespaces:
// C# version using Limilabs.FTP.Client;
' VB.NET version Imports Limilabs.FTP.Client
The following code uploads the file from disk to reports folder on the server, using FTP protocol:
// C# version
using (Ftp client = new Ftp())
{
client.Connect("ftp.example.com"); // or ConnectSSL for SSL
client.Login("user", "password");
client.Upload(@"reports\report.txt", @"c:\report.txt");
client.Close();
}
' VB.NET version
Using client As New Ftp()
client.Connect("ftp.example.com") ' or ConnectSSL for SSL
client.Login("user", "password")
client.Upload("reports\report.txt", "c:\report.txt")
client.Close()
End Using
You can also upload the file from memory:
// C# version
using (Ftp client = new Ftp())
{
client.Connect("ftp.example.com"); // or ConnectSSL for SSL
client.Login("user", "password");
byte[] bytes = Encoding.Default.GetBytes("Hello from Ftp.dll");
client.Upload(@"reports\report.txt", bytes);
client.Close();
}
' VB.NET version
Using client As New Ftp()
client.Connect("ftp.example.com") ' or ConnectSSL for SSL
client.Login("user", "password")
Dim bytes As Byte() = Encoding.[Default].GetBytes("Hello from Ftp.dll")
client.Upload("reportsreport.txt", bytes)
client.Close()
End Using
Finally you can also use overload that uses any Stream as the source.