<bdo id='GNefW'></bdo><ul id='GNefW'></ul>
<i id='GNefW'><tr id='GNefW'><dt id='GNefW'><q id='GNefW'><span id='GNefW'><b id='GNefW'><form id='GNefW'><ins id='GNefW'></ins><ul id='GNefW'></ul><sub id='GNefW'></sub></form><legend id='GNefW'></legend><bdo id='GNefW'><pre id='GNefW'><center id='GNefW'></center></pre></bdo></b><th id='GNefW'></th></span></q></dt></tr></i><div id='GNefW'><tfoot id='GNefW'></tfoot><dl id='GNefW'><fieldset id='GNefW'></fieldset></dl></div>

    1. <legend id='GNefW'><style id='GNefW'><dir id='GNefW'><q id='GNefW'></q></dir></style></legend>

        <tfoot id='GNefW'></tfoot>

        <small id='GNefW'></small><noframes id='GNefW'>

        直接上传新的 Ftp 列表框行

        Direct Uploading New Ftp listbox Lines(直接上传新的 Ftp 列表框行)
        1. <i id='G3e2u'><tr id='G3e2u'><dt id='G3e2u'><q id='G3e2u'><span id='G3e2u'><b id='G3e2u'><form id='G3e2u'><ins id='G3e2u'></ins><ul id='G3e2u'></ul><sub id='G3e2u'></sub></form><legend id='G3e2u'></legend><bdo id='G3e2u'><pre id='G3e2u'><center id='G3e2u'></center></pre></bdo></b><th id='G3e2u'></th></span></q></dt></tr></i><div id='G3e2u'><tfoot id='G3e2u'></tfoot><dl id='G3e2u'><fieldset id='G3e2u'></fieldset></dl></div>

            <small id='G3e2u'></small><noframes id='G3e2u'>

              • <bdo id='G3e2u'></bdo><ul id='G3e2u'></ul>
                  <tfoot id='G3e2u'></tfoot>

                    <tbody id='G3e2u'></tbody>
                • <legend id='G3e2u'><style id='G3e2u'><dir id='G3e2u'><q id='G3e2u'></q></dir></style></legend>
                  本文介绍了直接上传新的 Ftp 列表框行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我可以(上传/添加)列表框行到当前 ftp 列表框行服务器而不下载以前的 ftp 服务器列表框值.

                  而不是将添加的列表框行上传到 Ftp 列表框行服务器!

                  我可以简单地发送列表框新行,然后将其添加到当前列表框 ftp 服务器行(不删除旧行,它只添加新行)使用当前的 ftp 列表框行,而无需我下载和上传整个 ftp 列表框?

                  示例:这是我的代码

                  <块引用>

                  下载代码(按钮 1)[不重要]

                   Dim request As FtpWebRequest =WebRequest.Create("ftp://test.com/test.txt")request.Method = WebRequestMethods.Ftp.DownloadFilerequest.Credentials = New NetworkCredential("tester1",密码")使用响应作为 FtpWebResponse = request.GetResponse(),流作为 Stream = response.GetResponseStream(),阅读器作为 StreamReader = 新 StreamReader(stream)虽然不是 reader.EndOfStreamlistbox1.Items.Add(reader.ReadLine())结束时结束使用'添加列表框项目的在再次上传之前'listbox1.Items.Add(".")

                  <块引用>

                  上传代码(按钮 2)

                  [重要的是让它直接将新行上传到当前的 ftp 列表框线路服务器]

                   Dim request As FtpWebRequest =WebRequest.Create("ftp://test.com/test.txt")request.Method = WebRequestMethods.Ftp.UploadFilerequest.Credentials = New NetworkCredential("tester1",密码")request.UseBinary = False使用流作为 Stream = request.GetRequestStream(),作家作为 StreamWriter = 新 StreamWriter(流)对于索引 As Integer = 0 到 listbox1.Items.Count - 1writer.WriteLine(listbox1.Items(index))下一个结束使用抓住前任作为例外

                  问候

                  解决方案

                  注意:我看到您使用的是 Visual Studio 2012.可能不支持某些代码(.Net 版本是未标明).如果是这种情况,请发表评论.

                  WebRequest 支持 FTP APPE命令为其FtpWebRequest 化身.

                  请参阅 WebRequestMethods.Ftp → WebRequestMethods.Ftp.AppendFile.

                  此方法发送一个 Ftp APPE 命令.如果上传的文件存在,则会追加新的内容.
                  编写文本文件时,您可能需要附加 Environment.Newline 序列到每一行,如果/当需要.

                  由于您有一个 ListBox 控件,因此您可以提取其 Items 文本并以这种方式为每个项目字符串值添加换行符:

                  Dim TextLines As String() = listBox1.Items.Cast(Of String)().Select(Function(ln) Environment.NewLine + ln).ToArray()

                  你可以这样调用下面的方法:

                  Dim 结果 As Long = Await FtpAppenAsync("ftp://ftp.server.com/[EntryDir]/[ExistingFile]", TextLines)

                  这是一种修改后的方法,它允许将一些文本行附加到 FTP 服务器上的现有文本文件中:
                  (注意 StreamWriterEncoding:它设置为 Default → 当前本地代码页.
                  未指定编码时,默认为 UTF8.根据需要修改
                  ).

                  公共异步函数 FtpAppenAsync(ResourceName As String, TextData As String()) As Task(Of Integer)昏暗请求 As FtpWebRequest = CType(WebRequest.Create(ResourceName), FtpWebRequest)request.Credentials = New NetworkCredential("[FtpAccount]", "[FtpPassword]")request.Method = WebRequestMethods.Ftp.AppendFilerequest.UseBinary = Truerequest.UsePassive = TrueDim TextLinesWritten As Integer = 0尝试使用 ftpStream 作为 Stream = Await request.GetRequestStreamAsync()使用 ftpWriter 作为新的 StreamWriter(ftpStream, Encoding.Default)对于每个 TextLine 作为 TextData 中的字符串等待 ftpWriter.WriteAsync(TextLine)TextLinesWritten += 1Console.WriteLine("已上传 {0} 行", TextLinesWritten)下一个结束使用结束使用使用响应作为 FtpWebResponse = CType(Await request.GetResponseAsync(), FtpWebResponse)'Log-返回上传失败的StatusCode如果不是 (response.StatusCode = FtpStatusCode.ClosingData) 则返回 -1结束使用抓住前任作为例外'日志/报告前TextLinesWritten = -1扔结束尝试返回 TextLinesWritten结束功能

                  如果需要 Ssl 连接,请添加 Imports 和这些行:将它们粘贴到该方法的顶部:
                  (SecurityProtocolType取决于您的连接要求)

                  导入 System.Net.Security导入 System.Security.Cryptography.X509Certificates'方法代码ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12ServicePointManager.ServerCertificateValidationCallback =新 RemoteCertificateValidationCallback(Function(s, Cert, Chain, sslErrors)返回真结束函数)request.EnableSsl = True

                  Can i (Upload / Adding) Listbox Lines To Current Ftp listbox Lines Server Without download Previous ftp server Listbox value.

                  Instead of Uploading addition listbox lines To Ftp Listbox Lines Server !

                  Can I simply send listbox new lines and then it Added to currently listbox ftp server lines (without remove old lines, it only add new lines) With currently Ftp listbox Lines without me having to download and upload the whole ftp listbox?

                  Example : That's My Code

                  Download Code (Button 1) [not important]

                     Dim request As FtpWebRequest =
                     WebRequest.Create("ftp://test.com/test.txt")
                     request.Method = WebRequestMethods.Ftp.DownloadFile
                     request.Credentials = New NetworkCredential("tester1", 
                             "password")
                  
                          Using response As FtpWebResponse = request.GetResponse(),
                                    stream As Stream = response.GetResponseStream(),
                                    reader As StreamReader = New StreamReader(stream)
                              While Not reader.EndOfStream
                                  listbox1.Items.Add(reader.ReadLine())
                              End While
                          End Using
                  
                            ' Adding the listbox item's Before upload it again'
                  
                          listbox1.Items.Add(".")
                  

                  Upload Code (Button 2)

                  [important to make it direct upload new lines to currently ftp listbox lines server]

                                  Dim request As FtpWebRequest =
                                  WebRequest.Create("ftp://test.com/test.txt")
                                  request.Method = WebRequestMethods.Ftp.UploadFile
                                  request.Credentials = New NetworkCredential("tester1", 
                                 "password")
                                  request.UseBinary = False
                  
                                  Using stream As Stream = request.GetRequestStream(),
                                            writer As StreamWriter = New StreamWriter(stream)
                                      For index As Integer = 0 To listbox1.Items.Count - 1
                  
                                          writer.WriteLine(listbox1.Items(index))
                                      Next
                                  End Using
                  
                              Catch ex As Exception
                  

                  Regards

                  解决方案

                  Note: I see you're using Visual Studio 2012. There's the chance that some of the code might not be supported (the .Net version is not specified). Comment about it if that's the case.

                  WebRequest supports the FTP APPE command for its FtpWebRequest incarnation.

                  See the WebRequestMethods.Ftp → WebRequestMethods.Ftp.AppendFile.

                  This method sends an Ftp APPE command. If the uploaded file exists, it will append the new content.
                  When writing a text file, you may want to append an Environment.Newline sequence to each line, if/when need.

                  Since you have a ListBox control, you can extract its Items text and prepend a line feed to each item string value this way:

                  Dim TextLines As String() = listBox1.Items.Cast(Of String)().Select(Function(ln) Environment.NewLine + ln).ToArray()
                  

                  You can call the method that follows this way:

                  Dim result As Long = Await FtpAppenAsync("ftp://ftp.server.com/[EntryDir]/[ExistingFile]", TextLines)
                  

                  Here's a modified method that allows to append some text lines to an existing text file on an FTP Server:
                  (Take note about the Encoding of the StreamWriter: it's set to Default → current Local Codepage.
                  When an Encoding is not specified, it defaults to UTF8. Modify as required
                  ).

                  Public Async Function FtpAppenAsync(ResourceName As String, TextData As String()) As Task(Of Integer)
                  
                      Dim request As FtpWebRequest = CType(WebRequest.Create(ResourceName), FtpWebRequest)
                      request.Credentials = New NetworkCredential("[FtpAccount]", "[FtpPassword]")
                      request.Method = WebRequestMethods.Ftp.AppendFile
                      request.UseBinary = True
                      request.UsePassive = True
                  
                      Dim TextLinesWritten As Integer = 0
                      Try
                          Using ftpStream As Stream = Await request.GetRequestStreamAsync()
                              Using ftpWriter As New StreamWriter(ftpStream, Encoding.Default)
                                  For Each TextLine As String In TextData
                                      Await ftpWriter.WriteAsync(TextLine)
                                      TextLinesWritten += 1
                                      Console.WriteLine("Uploaded {0} lines", TextLinesWritten)
                                  Next
                              End Using
                          End Using
                          Using response As FtpWebResponse = CType(Await request.GetResponseAsync(), FtpWebResponse)
                              'Log-Return the StatusCode of the failed upload
                              If Not (response.StatusCode = FtpStatusCode.ClosingData) Then Return -1
                          End Using
                      Catch ex As Exception
                          'Log/report ex
                          TextLinesWritten = -1
                          Throw
                      End Try
                      Return TextLinesWritten
                  End Function
                  

                  If an Ssl connection is required, add the Imports and these lines: paste them on top of that method:
                  (The SecurityProtocolType depends on your connection requirements)

                  Imports System.Net.Security
                  Imports System.Security.Cryptography.X509Certificates
                  
                  'Method code
                  ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
                  
                  ServicePointManager.ServerCertificateValidationCallback =
                      New RemoteCertificateValidationCallback(Function(s, Cert, Chain, sslErrors)
                                                                  Return True
                                                              End Function)
                  request.EnableSsl = True
                  

                  这篇关于直接上传新的 Ftp 列表框行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  WPF ListBox not updating with the ItemsSource(WPF ListBox 未使用 ItemsSource 更新)
                  Problem getting list box items added through jquery in code behind(在后面的代码中通过 jquery 添加列表框项目时出现问题)
                  Selected item in list box is null(列表框中的选定项为空)
                  ASP.NET: Listbox datasource and databind(ASP.NET:列表框数据源和数据绑定)
                  .NET 3.5 Listbox Selected Values (Winforms)(.NET 3.5 列表框选定值(Winforms))
                  Why does the WPF listbox change selection on mouse button down rather than button up?(为什么 WPF 列表框在鼠标按下而不是按下按钮时更改选择?)
                  <i id='F8AjD'><tr id='F8AjD'><dt id='F8AjD'><q id='F8AjD'><span id='F8AjD'><b id='F8AjD'><form id='F8AjD'><ins id='F8AjD'></ins><ul id='F8AjD'></ul><sub id='F8AjD'></sub></form><legend id='F8AjD'></legend><bdo id='F8AjD'><pre id='F8AjD'><center id='F8AjD'></center></pre></bdo></b><th id='F8AjD'></th></span></q></dt></tr></i><div id='F8AjD'><tfoot id='F8AjD'></tfoot><dl id='F8AjD'><fieldset id='F8AjD'></fieldset></dl></div>
                    <tbody id='F8AjD'></tbody>
                • <small id='F8AjD'></small><noframes id='F8AjD'>

                          <bdo id='F8AjD'></bdo><ul id='F8AjD'></ul>

                          <tfoot id='F8AjD'></tfoot>

                          • <legend id='F8AjD'><style id='F8AjD'><dir id='F8AjD'><q id='F8AjD'></q></dir></style></legend>