• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Net.FtpWebRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Net.FtpWebRequest的典型用法代码示例。如果您正苦于以下问题:C# FtpWebRequest类的具体用法?C# FtpWebRequest怎么用?C# FtpWebRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FtpWebRequest类属于System.Net命名空间,在下文中一共展示了FtpWebRequest类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DownloadFtp

        /// <summary>
        /// 连接FTP的方法
        /// </summary>
        /// <param name="ftpuri">ftp服务器地址,端口</param>
        /// <param name="ftpUserID">用户名</param>
        /// <param name="ftpPassword">密码</param>
        public DownloadFtp(string ftpuri, string ftpUserID, string ftpPassword)
        {
            // 根据uri创建FtpWebRequest对象
              ft = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpuri));
              // ftp用户名和密码
              ft.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
              ft.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
             fr = (FtpWebResponse)ft.GetResponse();
              stream = fr.GetResponseStream();
              ////二进制文件读入
              //if (!fr.ContentType.ToLower().StartsWith("text/"))
              //{
              //    SaveBinaryFile(fr);
              //}
              ////文本文件
              //else
              //{
              string buffer = "", line;
              StreamReader reader = new StreamReader(stream);
              while ((line = reader.ReadLine()) != null)
              {
                  buffer += line + "\r\n";
              }

              //装入整个文件之后,接着就要把它保存为文本文件。
              SaveTextFile(buffer);
              //}
        }
开发者ID:kiichi7,项目名称:Search-Engine,代码行数:34,代码来源:DownloadFtp.cs


示例2: setProxyInfo

        private static void setProxyInfo(SetupConf setVariables, FtpWebRequest request)
        {
            try
            {
                string strProxyServer = setVariables.objProxyVariables.proxyServer.ToString();
                string strProxyPort = setVariables.objProxyVariables.proxyPort.ToString();
                string strProxyUsername = setVariables.objProxyVariables.proxyUsername.ToString();
                string strProxyPassword = setVariables.objProxyVariables.proxyPassword.ToString();

                IWebProxy proxy = request.Proxy;
                if (proxy != null)
                {
                    Console.WriteLine("Proxy: {0}", proxy.GetProxy(request.RequestUri));
                }

                WebProxy myProxy = new WebProxy();
                Uri newUri = new Uri(Uri.UriSchemeHttp + "://" + strProxyServer + ":" + strProxyPort);
                // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
                myProxy.Address = newUri;
                // Create a NetworkCredential object and associate it with the
                // Proxy property of request object.
                myProxy.Credentials = new NetworkCredential(strProxyUsername, strProxyPassword);
                request.Proxy = myProxy;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                Console.ReadLine();
                System.Environment.Exit(-1);
            }
        }
开发者ID:bbdserveranalyser,项目名称:bbdftpapplication,代码行数:31,代码来源:Program.cs


示例3: Upload

 /// <summary>
 /// 上傳檔案至FTP
 /// </summary>
 /// <param name="FilePath">要上傳的檔案來源路徑</param>
 /// <param name="FileName">要上傳的檔案名稱</param>
 /// <returns></returns>
 public static bool Upload(string FilePath,string FileName)
 {
     Uri FtpPath = new Uri(uriServer+FileName);
     bool result = false;
     try
     {
         ftpRequest = (FtpWebRequest)WebRequest.Create(FtpPath);
         ftpRequest.Credentials = new NetworkCredential(UserName, Password);
         ftpRequest.UsePassive = false;
         ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
         ftpFileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
         byte[] uploadBytes = new byte[ftpFileStream.Length];
         ftpFileStream.Read(uploadBytes, 0, uploadBytes.Length);
         ftpStream = ftpRequest.GetRequestStream();
         ftpStream.Write(uploadBytes, 0, uploadBytes.Length);
         ftpFileStream.Close();
         ftpStream.Close();
         ftpRequest = null;
         result = true;
     }
     catch (WebException ex)
     {
         sysMessage.SystemEx(ex.Message);
     }
     return result;
 }
开发者ID:coreychen71,项目名称:EWPCB-Project,代码行数:32,代码来源:ConnFTP.cs


示例4: uploadData

        /// <summary>
        /// Method to upload data to an ftp server
        /// </summary>
        public void uploadData()
        {
            Console.WriteLine("*** Beginning File Upload(s) ***");

            foreach (string afile in files)
            {
                Console.WriteLine("\t...writing out " + afile);
                //create a connection object
                ftpServer = connectionInfo.Split('|')[0];
                request = (FtpWebRequest)WebRequest.Create(new Uri(ftpServer + "/" + afile));
                request.Method = WebRequestMethods.Ftp.UploadFile;

                //set username and password
                userName = connectionInfo.Split('|')[1];
                userPassword = connectionInfo.Split('|')[2];
                request.Credentials = new NetworkCredential(userName, userPassword);

                //copy contents to server
                sourceStream = new StreamReader(programFilesAt + afile);
                byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                sourceStream.Close();
                request.ContentLength = fileContents.Length;
                requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();
                response = (FtpWebResponse)request.GetResponse();
                response.Close();
            }

            Console.WriteLine("\t File Uploads Complete");
        }
开发者ID:b1nary0mega,项目名称:HelperClasses,代码行数:34,代码来源:FTPxfr.cs


示例5: init

 private static void init(string method)
 {
     request = (FtpWebRequest) WebRequest.Create("ftp://" + server + path + file_name);
     request.Method = method;
     
     request.Credentials = new NetworkCredential("anonymous", "password");
 }
开发者ID:snoopy3476,项目名称:Emacs_Windows_Installer,代码行数:7,代码来源:Ftp.cs


示例6: GetVersion

        private static Boolean GetVersion(FtpWebRequest request)
        {
            Console.WriteLine("Checking Local Version...");
            var f = new StreamReader(@".\Connections\version.json");
            string data = f.ReadToEnd();
            versionsInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<VersionInfo>(data);

            credentials = new NetworkCredential(versionsInfo.ServerUserName,versionsInfo.ServerPassword);
            Console.WriteLine("Connecting to server...");
            request = (FtpWebRequest)WebRequest.Create(versionsInfo.ServerUrl + "Version.json");
            request.Credentials = credentials;
            request.Method = WebRequestMethods.Ftp.DownloadFile;
            Console.WriteLine("Downloading...");
            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);
            serverVersion = Newtonsoft.Json.JsonConvert.DeserializeObject<VersionInfo>(reader.ReadToEnd());
            Console.WriteLine("Close Server Connections...");
            reader.Close();
            response.Close();

            Console.WriteLine("Server Version : " + serverVersion.Version);
            Console.WriteLine("Local Version : " + versionsInfo.Version);
            f.Close();

            return versionsInfo.Version < serverVersion.Version;
            //Console.WriteLine(versionsInfo.Version);
            //f.ToString();
        }
开发者ID:Ruandv,项目名称:Training,代码行数:30,代码来源:Program.cs


示例7: DownloadFile

        public void DownloadFile(string remoteFile, string localFile)
        {
            // Создаем FTP Request
            ftpRequest = (FtpWebRequest)FtpWebRequest.Create(String.Format("{0}/{1}", host, remoteFile));
            // Инициализируем сетевые учетные данные
            ftpRequest.Credentials = new NetworkCredential(user, pass);

            ftpRequest.UseBinary = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive = true;

            // Задаем команду, которая будет отправлена на FTP-сервер
            ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
            ftpRequest.Timeout = TIMEOUT;
            // Ответ FTP-сервера
            ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
            // Возвращаем поток данных
            ftpStream = ftpResponse.GetResponseStream();
            // Создаем локальный файл
            FileStream localFileStream = new FileStream(localFile, FileMode.Create);
            // Пишем в файл
            ftpStream.CopyTo(localFileStream);

            localFileStream.Close();
            ftpStream.Close();
            ftpResponse.Close();
            ftpRequest = null;
        }
开发者ID:altaricka,项目名称:vDesign,代码行数:28,代码来源:FTPClient.cs


示例8: createDirectory

 /* Create a New Directory on the FTP Server */
 public bool createDirectory(string newDirectory)
 {
     bool result = true;
      try
      {
     /* Create an FTP Request */
     ftpRequest = (FtpWebRequest)WebRequest.Create(host + "/" + newDirectory);
     /* Log in to the FTP Server with the User Name and Password Provided */
     ftpRequest.Credentials = new NetworkCredential(user, pass);
     /* When in doubt, use these options */
     ftpRequest.UseBinary = true;
     ftpRequest.UsePassive = true;
     ftpRequest.KeepAlive = true;
     /* Specify the Type of FTP Request */
     ftpRequest.Method = WebRequestMethods.Ftp.MakeDirectory;
     /* Establish Return Communication with the FTP Server */
     ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
     /* Resource Cleanup */
     ftpResponse.Close();
     ftpRequest = null;
      }
      catch (Exception ex)
      {
     StockLog.Write(ex.ToString());
     result = false;
      }
      return result;
 }
开发者ID:dadelcarbo,项目名称:StockAnalyzer,代码行数:29,代码来源:StockFTP.cs


示例9: copyToServer

        public bool copyToServer(string remote, string local, string logPath)
        {
            bool success = false;
//            try
//            {
                ftpRequest = (FtpWebRequest)WebRequest.Create(host + remote);
                ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
                ftpRequest.Credentials = netCreds;

                byte[] b = File.ReadAllBytes(local);

                ftpRequest.ContentLength = b.Length;
                using (Stream s = ftpRequest.GetRequestStream())
                {
                    s.Write(b, 0, b.Length);
                }

                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                // check was successful
                if (ftpResponse.StatusCode == FtpStatusCode.ClosingData)
                {
                    success = true;
                    logResult(remote, host, user, logPath);
                }
                ftpResponse.Close();
                
/*            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }*/
            return success;
        }
开发者ID:keltie21,项目名称:PAXperiments,代码行数:33,代码来源:FTPconnection.cs


示例10: FtpWebResponse

		internal FtpWebResponse (FtpWebRequest request, Uri uri, string method, bool keepAlive)
		{
			this.request = request;
			this.uri = uri;
			this.method = method;
			//this.keepAlive = keepAlive;
		}
开发者ID:xzkmxd,项目名称:mono,代码行数:7,代码来源:FtpWebResponse.cs


示例11: VerificaSeExiste

        public bool VerificaSeExiste(string destinfilepath, string ftphost, string ftpfilepath, string user, string pass)
        {
            ftpRequest = (FtpWebRequest)FtpWebRequest.Create("ftp://" + ftphost + "//" + ftpfilepath);

            ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;

            ftpRequest.Credentials = new NetworkCredential(user, pass);

            ftpRequest.UseBinary = true;
            ftpRequest.UsePassive = true;
            ftpRequest.KeepAlive = true;

            try {
                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                ftpResponse.Close();                
                ftpRequest = null;
                return true;
            }
            catch (Exception exc)
            {
                this.sErro = exc.Message;                
                return false;
            }
             
        }
开发者ID:prasist,项目名称:wb20,代码行数:25,代码来源:ClasseFtp.cs


示例12: Connect

 private void Connect(string Path)
 {
     this.ftpRequest = (FtpWebRequest)WebRequest.Create(new Uri(Path));
     this.ftpRequest.UseBinary = true;
     this.ftpRequest.UsePassive = true;
     this.ftpRequest.KeepAlive = this._isKeepAlive;
     this.ftpRequest.Credentials = new NetworkCredential(this._userID, this._passWord);
 }
开发者ID:Yowe,项目名称:src,代码行数:8,代码来源:MyFtp.cs


示例13: setProxyAuthorization

 private static void setProxyAuthorization(SetupConf setVariables, FtpWebRequest request)
 {
     //Proxy configurations
     if (setVariables.objProxyVariables.proxyServer.ToString() != "PlaceHolder" && setVariables.objProxyVariables.proxyPort.ToString() != "PlaceHolder")
     {
         setProxyInfo(setVariables, request);
     }
 }
开发者ID:bbdserveranalyser,项目名称:bbdftpapplication,代码行数:8,代码来源:Program.cs


示例14: FTP

 public FTP(string requestUriString, string ftpUserID, string ftpPassword)
 {
     ftpRequest = FtpWebRequest.Create(requestUriString) as FtpWebRequest;
     ftpRequest.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
     ftpRequest.KeepAlive = false;
     ftpRequest.UsePassive = false;
     ftpRequest.UseBinary = true;
 }
开发者ID:lxh2014,项目名称:gigade-net,代码行数:8,代码来源:FTP.cs


示例15: RemoveDirectory

        public void RemoveDirectory(string ftpAddressPath, string directoryName)
        {
            this.FtpWebRequest = (FtpWebRequest)FtpWebRequest.Create(ftpAddressPath + directoryName);
            this.FtpWebRequest.Method = WebRequestMethods.Ftp.RemoveDirectory;
            this.FtpWebRequest.Credentials = new NetworkCredential(this.Username, this.Password);

            this.FtpWebRequest.GetResponse();
        }
开发者ID:poom-mon,项目名称:connect_DB,代码行数:8,代码来源:FTPConnector.cs


示例16: SetupFtpRequest

 /// <summary>
 /// Makes the FtpRequest object ready for a new request
 /// </summary>
 /// <param name="requestUrl"></param>
 private void SetupFtpRequest(string requestUrl)
 {
     // Set up the FtpRequest object
     this.FtpRequest = (FtpWebRequest)FtpWebRequest.Create(requestUrl);
     this.FtpRequest.Credentials = this.Credenntials;
     this.FtpRequest.KeepAlive = true;
     this.FtpRequest.UsePassive = true;
     this.FtpRequest.ConnectionGroupName = Host;
 }
开发者ID:RononDex,项目名称:Sun.Plasma,代码行数:13,代码来源:FtpClient.cs


示例17: FtpDataStream

		internal FtpDataStream (FtpWebRequest request, Stream stream, bool isRead)
		{
			if (request == null)
				throw new ArgumentNullException ("request");

			this.request = request;
			this.networkStream = stream;
			this.isRead = isRead;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:9,代码来源:FtpDataStream.cs


示例18: GetFile

        public byte[] GetFile(string filePath)
        {
            try
            {
                /* Create an FTP Request */
                ftpRequest = (FtpWebRequest)FtpWebRequest.Create(host + "/" + filePath);
                /* Log in to the FTP Server with the User Name and Password Provided */
                ftpRequest.Credentials = new NetworkCredential(user, pass);
                /* When in doubt, use these options */
                ftpRequest.UseBinary = true;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive = true;
                /* Specify the Type of FTP Request */
                ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
                /* Establish Return Communication with the FTP Server */
                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                /* Get the FTP Server's Response Stream */
                ftpStream = ftpResponse.GetResponseStream();
                /* Open a File Stream to Write the Downloaded File */
                /* Buffer for the Downloaded Data */
                byte[] byteBuffer = new byte[bufferSize];
                int bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);

                /* Download the File by Writing the Buffered Data Until the Transfer is Complete */
                try
                {
                    while (bytesRead > 0)
                    {

                        bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
                    }
                }
                catch (Exception ex) { Console.WriteLine(ex.ToString()); }
                /* Resource Cleanup */
                ftpStream.Close();
                ftpResponse.Close();
                ftpRequest = null;

                var nullCount = 0;
                var listInt = new List<byte>();
                var i = 1;
                foreach (var b in byteBuffer)
                {
                    if (nullCount < 3)
                    {
                        listInt.Add(b);
                    }
                    if (b == 0 && i == 0)
                        nullCount++;
                    i = b;
                }
                return listInt.ToArray();
            }
            catch (Exception ex) { Console.WriteLine(ex.ToString()); }
            return new byte[1];
        }
开发者ID:pashaiva,项目名称:psub.Web,代码行数:56,代码来源:FTP.cs


示例19: DoLogin

 /// <summary>
 /// 
 /// </summary>
 /// <param name="url"></param>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public static bool DoLogin(string url,string username, string password)
 {
     Request = (FtpWebRequest)FtpWebRequest.Create(url);
     Request.Method = WebRequestMethods.Ftp.UploadFile;
     Request.Credentials = new NetworkCredential(username, password);
     Request.UsePassive = true;
     Request.UseBinary = true;
     Request.KeepAlive = false;
     return true;
 }
开发者ID:timotei,项目名称:InfoCenter,代码行数:17,代码来源:UploadManager.cs


示例20: testConnection

 public bool testConnection()
 {
     ftpRequest = (FtpWebRequest)WebRequest.Create(host);
     ftpRequest.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;
     ftpRequest.Credentials = netCreds;
     if (ftpRequest.GetResponse() != null)
     {
         return true;
     }
     return false;
 }
开发者ID:keltie21,项目名称:PAXperiments,代码行数:11,代码来源:FTPconnection.cs



注:本文中的System.Net.FtpWebRequest类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Net.FtpWebResponse类代码示例发布时间:2022-05-26
下一篇:
C# Net.EndPoint类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap