0
今天我第一次嘗試了C#。我想上傳一個文件夾到FTP服務器並使用這個FTP CLass:http://www.codeproject.com/Tips/443588/Simple-Csharp-FTP-ClassFTP類未使用
現在,當我使用方法時,它說「名稱ftpClient在該上下文中不存在」。我將複製我的代碼:
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));
}
}
}
}
到目前爲止,我明白了,你從未聲明/初始化'ftpClient'。 –
某處應該是'var ftpClient = new FTPClient()' – paqogomez
請提供一個[Minimal,Complete and Verifiable](http://stackoverflow.com/help/mcve)示例代碼。 – milo526