LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

【C#】兩個(gè)FTP服務(wù)器之間傳送數(shù)據(jù)

admin
2021年10月16日 14:36 本文熱度 3567
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Text;
 
public class FtpUpDown
{
    string ftpServerIPout;
    string ftpServerIPin;
    string ftpUserIDout;
    string ftpUserIDin;
    string ftpPasswordout;
    string ftpPasswordin;
    FtpWebRequest reqFTPout;
    FtpWebRequest reqFTPin;
 
   public FtpUpDown(string ftpServerIPout, string ftpUserIDout,string ftpPasswordout,string ftpServerIPin, string ftpUserIDin ,string ftpPasswordin)
   {
 
        this.ftpServerIPout = ftpServerIPout;
        this.ftpServerIPin=ftpServerIPin;
        this.ftpUserIDout = ftpUserIDout;
        this.ftpUserIDin = ftpUserIDin;
        this.ftpPasswordout = ftpPasswordout;
        this.ftpPasswordin = ftpPasswordin;
 
    }
    private void Connect(string pathout, string pathin)//連接ftp
    {
        // 根據(jù)uri創(chuàng)建FtpWebRequest對象
        reqFTPout = (FtpWebRequest)FtpWebRequest.Create(new Uri(pathout));
        // 指定數(shù)據(jù)傳輸類型
        reqFTPout.UseBinary = true;
        // ftp用戶名和密碼
        reqFTPout.Credentials = new NetworkCredential(ftpUserIDout, ftpPasswordout);
        reqFTPout.Method=WebRequestMethods.Ftp.DownloadFile;
        // 根據(jù)uri創(chuàng)建FtpWebRequest對象
        reqFTPin = (FtpWebRequest)FtpWebRequest.Create(new Uri(pathin));
        // 指定數(shù)據(jù)傳輸類型
        reqFTPin.UseBinary = true;
        // ftp用戶名和密碼
        reqFTPin.Credentials = new NetworkCredential(ftpUserIDin, ftpPasswordin);
        reqFTPin.Method = WebRequestMethods.Ftp.UploadFile;
    }
   public bool Download(string fileName)/**/////上面的代碼實(shí)現(xiàn)了從ftp服務(wù)器下載文件的功能
   {
       try
       {
            string urlout = "ftp://" + ftpServerIPout + "/" + fileName;
            string urlin = "ftp://" + ftpServerIPin + "/" + fileName;
            Connect(urlout, urlin);//連接
            FtpWebResponse response = (FtpWebResponse)reqFTPout.GetResponse();
            Stream ftpStream = response.GetResponseStream();
            long cl = response.ContentLength;
            int bufferSize = 2048;
            int readCount;
            byte[] buffer = new byte[bufferSize];
            readCount = ftpStream.Read(buffer, 0, bufferSize);
            Stream strm = reqFTPin.GetRequestStream();
            while (readCount != 0)
            {
                strm.Write(buffer, 0, bufferSize);
                readCount = ftpStream.Read(buffer, 0, bufferSize);
            }
            ftpStream.Close();
            strm.Close();
            response.Close();
            return true;
       }
       catch
       {
            return false;
 
       }
    }
       
    }
 
后臺調(diào)用:
 
protected void Button1_Click(object sender, EventArgs e)
    {
          FtpUpDown ftpUpDown = new FtpUpDown("192.168.0.26", "tfds", "tfds","192.168.0.34","tfds","tfds");
          ftpUpDown.Download("2.txt");
          Response.Write("success");
 
    }

該文章在 2021/10/16 14:36:18 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場、車隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

黄频国产免费高清视频,久久不卡精品中文字幕一区,激情五月天AV电影在线观看,欧美国产韩国日本一区二区
欧美精品中文字幕第九在线 | 中出受孕中文字幕在线 | 一本一级特黄大片中文字幕 | 中文字幕在线观看 | 尤物九九久久国产精品 | 日本韩国欧美一区二区三区 |