FTP类未使用 [英] FTP Class not used

查看:124
本文介绍了FTP类未使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我第一次尝试了C#。我想上传一个文件夹到FTP服务器并使用这个FTP CLass: http ://www.codeproject.com/Tips/443588/Simple-Csharp-FTP-Class



现在,当我使用方法时,它说名称ftpClient在该上下文中不存在。我将复制我的代码:

  using System; 
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.IO;
使用System.Net
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;


命名空间DaloCloud
{

public partial class Form1:Form
{
static int x = 200; //帮助屏幕
static int y = 200; //帮助屏幕
字符串用户名; //存储在那里的FTP-Username值
字符串密码; //存储在那里的FTP-Password值
字符串dirPath; // C:\DaloUpload
string uploadPath; // ftp:// daloserver / users / username / files
$ b $ public Form1()
{
InitializeComponent();

$ b $ private void Form1_Load(object sender,EventArgs e)
{

}

private void pictureBox1_Click(object sender,EventArgs e)
{

}

private void helpButton_Click(object sender,EventArgs e)
{
//创建一个Form2的新实例并将其Visible属性设置为true。
Form2 form2 = new Form2();
form2.Visible = true;


$ b $ private void usernameTextbox_TextChanged(object sender,EventArgs e)
{
username = usernameTextbox.Text;
}

private void passwordTextbox_TextChanged(object sender,EventArgs e)
{
password = passwordTextbox.Text;

$ b private void connectButton_Click(object sender,EventArgs e)
{
string [] files = Directory.GetFiles(dirPath,*。*);
string [] subDirs = Directory.GetDirectories(dirPath);

foreach(文件中的字符串文件)
{
ftpClient.upload(uploadPath +/+ Path.GetFileName(file),file);
}

foreach(subDir中的字符串subDir)
{
ftpClient.createDirectory(uploadPath +/+ Path.GetFileName(subDir));
recursiveDirectory(subDir,uploadPath +/+ Path.GetFileName(subDir));
}
}
}
}


解决方案

在C#中,您必须先声明变量,然后才能使用它们。您还没有声明任何名为 ftpClient 的变量。



这个错误告诉你很简洁: ftpClient 在您使用它的地方不存在。你必须声明它存在。



可能看起来像这样:

  FTPClient ftpClient = new FTPClient(); 


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:

FTPClient ftpClient = new FTPClient();

这篇关于FTP类未使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆