ftp上传到多个ftp服务器 [英] Ftp upload to multiple ftp servers

查看:156
本文介绍了ftp上传到多个ftp服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要与此代码相关的帮助才能将一个exe文件上传到多个ftp服务器.
我有一个包含我需要的所有链接以及用户名和密码的文件,现在它每次都仅在第一次上载后,才收到错误无效的uri,即使它是正确的.


-------------------------------------------------- ---------------------

Hi i need help with this code to upload one exe to multiple ftp servers.
i have a file with all the links i need and user names and passwords , now it only uploads the first time every on after that gets the error invalid uri even though its correct.


-----------------------------------------------------------------------

Imports System.Net
Imports System.IO
Imports System.Data.SqlClient
Public Class Formftp

  Private Sub Buttonftp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonftp.Click
    Dim locat, combind, str As String
    locat = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location)

    combind = System.IO.Path.Combine(locat, "FTPstr.cfg")

    Dim reader As New StreamReader(combind)

    str = reader.ReadToEnd()

    Dim TestArray() As String = str.Split(",")
    Dim strftp As String
    Dim s As Boolean

    For t As Integer = 0 To TestArray.Length - 1
      strftp = TestArray(t).ToString()
      Dim TestFTPArray() As String = strftp.Split("/")


      ' make a reference to a directory
      Dim di As New IO.DirectoryInfo(locat + "\ftp")
      Dim diar1 As IO.FileInfo() = di.GetFiles()
      Dim dra As IO.FileInfo

      'list the names of all files in the specified directory

      For Each dra In diar1
        Try

          Dim struri As String = String.Format("ftp://{0}/{1}/{2}", TestFTPArray(0), TestFTPArray(1), dra)

          Dim clsRequest As System.Net.FtpWebRequest = _
           DirectCast(System.Net.WebRequest.Create(struri), System.Net.FtpWebRequest)

          clsRequest.Credentials = New System.Net.NetworkCredential(TestFTPArray(2), TestFTPArray(3))
          clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

          ' read in file...
          Dim st As String = String.Format("{0}{1}{2}", locat, "\ftp\", dra)
          Dim bFile() As Byte = System.IO.File.ReadAllBytes(st)

          ' upload file...
          Dim clsStream As System.IO.Stream = _
              clsRequest.GetRequestStream()
          clsStream.Write(bFile, 0, bFile.Length)
          clsStream.Close()
          clsStream.Dispose()
          clsRequest.Abort()

        Catch ex As Exception

        End Try

      Next


        ' set up request...
    Next

  End Sub
End Class




更新2012/07/30:
我使用一个exe(试图将其放置到多个服务器)进行了测试,将其上载到第一个ftp服务器,然后在连接到第二个和每个ftp服务器时显示无效的URI:无法解析主机名".在(




update 2012/07/30:
i tested with one exe(trying to put it to multiple servers) it uploads it to the first ftp server then when connecting to the second and every ftp server after it it says "Invalid URI: The hostname could not be parsed." on the (

Dim clsRequest As System.Net.FtpWebRequest = _
           DirectCast(System.Net.WebRequest.Create(struri), System.Net.FtpWebRequest)

)行
即使我可以在浏览器中使用与用户名和密码完全相同的目标ftp://ip/folder/,也要在文件中读取用户名和密码,然后在浏览器中打开ftp文件夹.因此ftp文件夹本身没有问题,只是代码不想将exe通过ftp传输到第二个或第三个ftp服务器.

) line
even though i can use the exact same destination ftp://ip/folder/ in a browser ect with the username and password as is in the file it is reading and open the ftp folder in the browser. So there is no problem with the ftp folder itself , just the code doesn''t want to ftp the exe to a second or third ftp server.

推荐答案

首先进行一些基本的调试,因此您可以提出比修复我的代码"更具体的问题.

1)在调试器中运行它.陷阱在每个FTP连接上..它到达那里两次了吗?

2)在代码中添加一些状态打印,以查看其试图执行的操作..它如何解析您的配置..等等.
You should start with some basic debugging so you can ask a more specific question than ''fix my code''.

1) run it in a debugger. Trap on each FTP connect.. does it get there twice?

2) add some status prints to your code to see what it is trying to do.. how it is parsing your configuration.. etc.


这篇关于ftp上传到多个ftp服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆