VeviFTP.VeviFtpHelper ftp;
/// <summary>
/// 连接FTP
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
if (ftp != null)
ftp.Dispose();
ftp = new VeviFTP.VeviFtpHelper(textBox1.Text,textBox6.Text, textBox2.Text, textBox3.Text);
ftp.ShowErrorEvent += new VeviFTP.ShowError(ftp_ShowErrorEvent);
if (ftp.PrepareFTPInfo())
{
if (ftp.ExitFTP())
{
richTextBox1.AppendText("连接成功!" + "\r\n");
}
}
}
void ftp_ShowErrorEvent(string content, string title)
{
richTextBox1.AppendText(content + " " + title + "\r\n");
}
private string PreparePath()
{
if (ftp == null)
return "";
return ftp.FTPRootURI + textBox4.Text;
}
/// <summary>
/// 文件列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button2_Click(object sender, EventArgs e)
{
string path = PreparePath();
string info;
IList<string> fileList = ftp.GetFileList(path,out info);
if (info == "1")
{
foreach (string str in fileList)
richTextBox1.AppendText(str+"\r\n");
}
}
/// <summary>
/// 文件夹列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, EventArgs e)
{
string path = PreparePath();
string info;
IList<string> fileList = ftp.GetFolderList(path, out info);
if (info == "1")
{
foreach (string str in fileList)
richTextBox1.AppendText(str + "\r\n");
}
}
/// <summary>
/// 上传文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, EventArgs e)
{
OpenFileDialog opdiag = new OpenFileDialog();
opdiag.Filter = "所有文件(*.*)|*.*";
//
string path = PreparePath();
if (opdiag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if(ftp.UploadFile(path, opdiag.FileName))
richTextBox1.AppendText("上传文件成功!" + "\r\n");
}
}
/// <summary>
/// 创建文件夹
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button6_Click(object sender, EventArgs e)
{
string path = PreparePath();
if ( ftp.CreateFolder(path))
{
richTextBox1.AppendText("创建文件夹成功!" + "\r\n");
}
}
/// <summary>
/// 删除文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button7_Click(object sender, EventArgs e)
{
string path = PreparePath();
if (ftp.DeleteFile(path))
{
richTextBox1.AppendText("删除文件成功!" + "\r\n");
}
}
/// <summary>
/// 下载文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button5_Click(object sender, EventArgs e)
{
FolderBrowserDialog fdiag = new FolderBrowserDialog();
string path = PreparePath();
if (fdiag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
if (ftp.DownLoadFile(path,fdiag.SelectedPath))
{
richTextBox1.AppendText("下载文件成功!" + "\r\n");
}
}
}
private void button9_Click(object sender, EventArgs e)
{
string path = PreparePath();
if (ftp.DeleteFolder(path))
{
richTextBox1.AppendText("删除文件夹成功!" + "\r\n");
}
}
private void button8_Click(object sender, EventArgs e)
{
string path = PreparePath();
string newName = textBox5.Text;
if (ftp.ReName(path, newName))
{
richTextBox1.AppendText("重命名成功!" + "\r\n");
}
}
VeviFTPHelper应用实例
最新推荐文章于 2022-09-26 15:08:46 发布