当前位置: 首页>>代码示例>>C#>>正文


C# Net.FtpWebRequest类代码示例

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


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


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