today I tried C# for the first time. I want to upload a folder to an FTP Server and used this FTP CLass: http://www.codeproject.com/Tips/443588/Simple-Csharp-FTP-Class
Now, when I use the Methods, it Says "Name ftpClient does not exist in that context". I will copy my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Net
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DaloCloud
{
public partial class Form1 : Form
{
static int x = 200; // For Help-Screen
static int y = 200; // For Help-Screen
string username; // FTP-Username Value stored in there
string password; // FTP-Password Value stored in there
string dirPath; // C:\DaloUpload
string uploadPath; // ftp: //daloserver/users/username/files
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void helpButton_Click(object sender, EventArgs e)
{
// Create a new instance of Form2 and set its Visible property to true.
Form2 form2 = new Form2();
form2.Visible = true;
}
private void usernameTextbox_TextChanged(object sender, EventArgs e)
{
username = usernameTextbox.Text;
}
private void passwordTextbox_TextChanged(object sender, EventArgs e)
{
password = passwordTextbox.Text;
}
private void connectButton_Click(object sender, EventArgs e)
{
string[] files = Directory.GetFiles(dirPath, "*.*");
string[] subDirs = Directory.GetDirectories(dirPath);
foreach (string file in files)
{
ftpClient.upload(uploadPath + "/" + Path.GetFileName(file), file);
}
foreach (string subDir in subDirs)
{
ftpClient.createDirectory(uploadPath + "/" + Path.GetFileName(subDir));
recursiveDirectory(subDir, uploadPath + "/" + Path.GetFileName(subDir));
}
}
}
}
In C#, you have to declare variables before you can use them. You haven't declared any variable named
ftpClient
.This error is telling you quite concisely that
ftpClient
doesn't exist at the point you are using it. You must declare it to make it exist.Might looks something like this: