Professional Documents
Culture Documents
Simple FTP Upload
Simple FTP Upload
bool success;
ftp.Hostname = "ftp.chilkatsoft.com";
ftp.Username = "****";
ftp.Password = "****";
// Upload a file.
string localFilename;
localFilename = "hamlet.xml";
string remoteFilename;
remoteFilename = "hamlet.xml";
success = ftp.PutFile(localFilename,remoteFilename);
if (success != true) {
MessageBox.Show(ftp.LastErrorText);
return;
}
ftp.Disconnect();
MessageBox.Show("File Uploaded!");
Passive FTP Upload
Download Chilkat .NET for 2.0 / 3.5 Framework
bool success;
ftp.Hostname = "www.example-code.com";
ftp.Username = "****";
ftp.Password = "****";
// Upload a file.
string localFilename;
localFilename = "hamlet.xml";
string remoteFilename;
remoteFilename = "hamlet.xml";
success = ftp.PutFile(localFilename,remoteFilename);
if (success != true) {
MessageBox.Show(ftp.LastErrorText);
return;
}
ftp.Disconnect();
MessageBox.Show("File Uploaded!");
bool success;
ftp.Hostname = "www.example-code.com";
ftp.Username = "****";
ftp.Password = "****";
// Download a file.
string localFilename;
localFilename = "hamlet.xml";
string remoteFilename;
remoteFilename = "hamlet.xml";
success = ftp.GetFile(remoteFilename,localFilename);
if (success != true) {
MessageBox.Show(ftp.LastErrorText);
return;
}
ftp.Disconnect();
MessageBox.Show("File Downloaded!");
Simple example to download a file from an FTP server using passive mode.
bool success;
ftp.Hostname = "www.example-code.com";
ftp.Username = "****";
ftp.Password = "****";
// Download a file.
string localFilename;
localFilename = "hamlet.xml";
string remoteFilename;
remoteFilename = "hamlet.xml";
success = ftp.GetFile(remoteFilename,localFilename);
if (success != true) {
MessageBox.Show(ftp.LastErrorText);
return;
}
ftp.Disconnect();
MessageBox.Show("File Downloaded!");
Rename a remote file or directory. The RenameRemoteFile can be called to rename either a
remote file or directory.
bool success;
ftp.Hostname = "ftp.myFtpServer123.com";
ftp.Username = "***";
ftp.Password = "***";
ftp.Disconnect();
Delete
Chilkat.Ftp2 ftp = new Chilkat.Ftp2();
bool success;
ftp.Hostname = "ftp.chilkatsoft.com.com";
ftp.Username = "myLogin";
ftp.Password = "myPassword";
success = ftp.DeleteRemoteFile("goodbye.txt");
if (success != true) {
MessageBox.Show(ftp.LastErrorText);
return;
}
ftp.Disconnect();
File Existence Check
Download Chilkat .NET for 2.0 / 3.5 Framework
Testing to see if a file exists on the FTP server. The GetSizeByName method is a convenient
way to check if a file exists. It will return -1 if the file does not exist, otherwise it returns the size
of the file in bytes.
bool success;
ftp.Hostname = "ftp.***.com";
ftp.Username = "***";
ftp.Password = "***";
// Test to see if the file exists by getting the file size by name.
// If a -1 is returned, the file does not exist.
int fileSize;
fileSize = ftp.GetSizeByName("test123.txt");
if (fileSize < 0) {
textBox1.Text += "file does not exist" + "\r\n";
}
else {
textBox1.Text += "file exists and is " + Convert.ToString(fileSize)
+ " bytes in size" + "\r\n";
}
ftp.Disconnect();
FTP Upload with Progress Monitoring
Download Chilkat .NET for 2.0 / 3.5 Framework
Demonstrates how to upload a file to an FTP server with progress monitoring event
callbacks. Also demonstrates how to abort an FTP upload while in progress.
ftp.Hostname = "ftp.chilkatsoft.com";
ftp.Username = "***";
ftp.Password = "***";
ftp.EnableEvents = true;
ftp.OnFtpPercentDone += new
Ftp2.FtpPercentDoneEventHandler(OnFtpPercentDone);
Demonstrates how to download a file from an FTP server with progress monitoring event
callbacks. Also demonstrates how to abort an FTP download while in progress.
ftp.Hostname = "ftp.chilkatsoft.com";
ftp.Username = "****";
ftp.Password = "****";
ftp.EnableEvents = true;
ftp.OnFtpPercentDone += new
Ftp2.FtpPercentDoneEventHandler(OnFtpPercentDone);
// Connect and login.
bool success = ftp.Connect();
if (success)
{
// Download a file
success =
ftp.GetFile("ChilkatZipSE.exe","ChilkatZipSE.exe");
if (success)
{
MessageBox.Show("Done!");
}
else
{
MessageBox.Show(ftp.LastErrorText);
}
}
else
{
MessageBox.Show(ftp.LastErrorText);
}
}