netdragon-cai


        public void SyncToDownloadServer(string server, string filePath, string fileName)
        {
            var username = "ccccaa1";
            var password = "test";

            string ftpfullpath = "ftp://" + server + "/" + fileName;
            FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
            ftp.Credentials = new NetworkCredential(username, password);
            //userid and password for the ftp server to given  

            ftp.KeepAlive = true;
            ftp.UseBinary = true;
            ftp.UsePassive = false;

            ftp.Method = WebRequestMethods.Ftp.UploadFile;
            FileStream fs = File.OpenRead(filePath);
            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);

            fs.Close();
            Stream ftpstream = ftp.GetRequestStream();
            ftpstream.Write(buffer, 0, buffer.Length);
            ftpstream.Close();


        }

分类:

技术点:

相关文章: