.net下封转的FTP类,实现局域网内大文件批量传输Part2

这是一个.NET应用示例,通过FTPclient类实现在局域网内的大文件批量上传功能。代码中包含了目录遍历、文件上传及文件类型的校验,确保上传文件的安全性。背景是在AlumnusManage项目中,用于班级、教师和校友资料的上传。

后台代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.IO;
using System.Xml;
using System.Net;
using BLL;

namespace AlumnusManage
{
    public partial class UploadData : UserControl
    {
        private FTPclient myFTPclient;
        private XY myXY = new XY();
        private List<string> fileName = new List<string>();
        private bool checkFlog = false;
        private bool uploadFLog = false;
        private bool checkedFlog = false;

        public UploadData()
        {
            InitializeComponent();
            this.BackColor = Main.bgColor;
            dataGridView1.BackgroundColor = Main.bgColor;
        }
        ~UploadData()
        {
            myFTPclient = null;
        }

        public static string GetLinkStr(string _key)
        {
            string filePath = AppDomain.CurrentDomain.BaseDirectory.ToString() + "AlumnusManage.exe.config";

            XmlDocument myDoc = new XmlDocument();
            myDoc.Load(filePath);
            XmlNode objContentNode = myDoc.SelectSingleNode("//appSettings");    //声明XmlNode对象    
            //  
            XmlElement xElem1 = (XmlElement)objContentNode.SelectSingleNode("//add[@key='" + _key + "']");

            string str = xElem1.GetAttribute("value");
            string key = "Rainight";

            DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
            provider.Key = Encoding.ASCII.GetBytes(key.Substring(0, 8));
            provider.IV = Encoding.ASCII.GetBytes(key.Substring(0, 8));
            byte[] buffer = new byte[str.Length / 2];
            for (int i = 0; i < (str.Length / 2); i++)
            {
                int num2 = Convert.ToInt32(str.Substring(i * 2, 2), 0x10);
                buffer[i] = (byte)num2;
            }

            MemoryStream stream = new MemoryStream();
            CryptoStream stream2 = new CryptoStream(stream, provider.CreateDecryptor(), CryptoStreamMode.Write);
            stream2.Write(buffer, 0, buffer.Length);
            stream2.FlushFinalBlock();
            stream.Close();
            return Encoding.GetEncoding("GB2312").GetString(stream.ToArray());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            pictureBox1.Visible = true;
            myFTPclient = new FTPclient(GetLinkStr("IPAddr"), "xyb_upload", "xyb2010shujushangchuan");
            myFTPclient.port = 8765;

 &nb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值