当前位置:编程学习 > C#/ASP.NET >>

服务器和服务器之间FTP传输文件

先在要实现 比如 要把 10.10.10.15 这个服务器 上的文件 传到

文件服务器 10.10.10.16 上去 知道它的 ftp 用户名和密码

最好c#代码实现
奉送60分 哈 --------------------编程问答-------------------- 不如用批处理文件,呵呵。
ftp -n -s:fn.txt 10.10.10.16 

fn.txt内容:
user ftp帐号
密码
put 本地路径  服务器路径
bye --------------------编程问答-------------------- 看看这个吧:

http://hi.baidu.com/airfan/blog/item/af5e9d13aab4e1806438db7d.html

有实现FTP上传和下载的代码

你可以把它们结合起来,不用下载到本地,取到数据后直接往另一台服务器写 --------------------编程问答-------------------- 学习一下 --------------------编程问答-------------------- #region "Download: File transfer FROM ftp server" 
        /// <summary> 
        /// Copy a file from FTP server to local 
        /// </summary> 
        /// <param name="sourceFilename">Target filename, if required </param> 
        /// <param name="localFilename">Full path of the local file </param> 
        /// <returns> </returns> 
        /// <remarks>Target can be blank (use same filename), or just a filename 
        /// (assumes current directory) or a full path and filename </remarks> 
        public bool Download(string sourceFilename, string localFilename, bool PermitOverwrite) 
        { 
            //2. determine target file 
            FileInfo fi = new FileInfo(localFilename); 
            return this.Download(sourceFilename, fi, PermitOverwrite); 
        } 

        //Version taking an FtpFileInfo 
        public bool Download(FtpFileInfo file, string localFilename, bool permitOverwrite) 
        { 
            return this.Download(file.FullName, localFilename, permitOverwrite); 
        } 

        //Another version taking FtpFileInfo and FileInfo 
        public bool Download(FtpFileInfo file, FileInfo localFI, bool permitOverwrite) 
        { 
            return this.Download(file.FullName, localFI, permitOverwrite); 
        } 

        //Version taking string/FileInfo 
        public bool Download(string sourceFilename, FileInfo targetFI, bool permitOverwrite) 
        { 
            //1. check target 
            if (targetFI.Exists && !(permitOverwrite)) 
            { 
                throw (new ApplicationException("Target file already exists")); 
            } 

            //2. check source 
            string target; 
            if (sourceFilename.Trim() == "") 
            { 
                throw (new ApplicationException("File not specified")); 
            } 
            else if (sourceFilename.Contains("/")) 
            { 
                //treat as a full path 
                target = AdjustDir(sourceFilename); 
            } 
            else 
            { 
                //treat as filename only, use current directory 
                target = CurrentDirectory + sourceFilename; 
            } 

            string URI = Hostname + target; 

            //3. perform copy 
            System.Net.FtpWebRequest ftp = GetRequest(URI); 

            //Set request to download a file in binary mode 
            ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile; 
            ftp.UseBinary = true; 

            //open request and get response stream 
            using (FtpWebResponse response = (FtpWebResponse)ftp.GetResponse()) 
            { 
                using (Stream responseStream = response.GetResponseStream()) 
                { 
                    //loop to read & write to file 
                    using (FileStream fs = targetFI.OpenWrite()) 
                    { 
                        try 
                        { 
                            byte[] buffer = new byte[2048]; 
                            int read = 0; 
                            do 
                            { 
                                read = responseStream.Read(buffer, 0, buffer.Length); 
                                fs.Write(buffer, 0, read); 
                            } while (!(read == 0)); 
                            responseStream.Close(); 
                            fs.Flush(); 
                            fs.Close(); 
                        } 
                        catch (Exception) 
                        { 
                            //catch error and delete file only partially downloaded 
                            fs.Close(); 
                            //delete target file as it's incomplete 
                            targetFI.Delete(); 
                            throw; 
                        } 
                    } 

                    responseStream.Close(); 
                } 

                response.Close(); 
            } 


            return true; 
        } 
        #endregion --------------------编程问答-------------------- 有个小程序发给你,把邮箱给我好了
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,