2013-03-31 2 views
2

로컬 디렉토리에없는 모든 파일을 다운로드 할 FTP 서버가 있습니다.주어진 로컬 파일 목록에 FTP가없는 경우 파일을 다운로드하십시오.

나는 For Next을 시도했지만 주위를 둘러 볼 수 없습니다. 파일을 열거하려고했지만 두 목록 모두에 대해 수행 한 결과로 오류가 발생했습니다. 나는이 오류가 로컬 목록의 개별 열거 형 파일로 온라인 파일을 검사하는 것으로 인해 발생할 수 있다고 생각한다. 이 문제를 어떻게 해결합니까? FTPClient 클래스 코드에

링크 :

https://docs.google.com/file/d/0BxFwEuHe1g77TEw2ckZxVUlQdGM/edit?usp=sharing

모든 코드 :

  Dim ftp As New FTPclient("ftp://www.ahpg.zxq.net", "eg", "eg") 

    Dim dirList As FTPdirectory = ftp.ListDirectoryDetail("/") 
    Dim result As List(Of String) = ftp.ListDirectory("/") 
    For Each line As String In result 
     FTPLBX.Items.Add(line) 
    Next 
    Dim str As String 
    Dim locstr As String 
    Dim res_numer As IEnumerator 
    res_numer = result.GetEnumerator() 
    Dim loclist As List(Of String) = New List(Of String) _ 
            (System.IO.Directory.EnumerateFiles("C:/Program Files/Business Elements/Recent Files")) 
    Dim LOC_Enum As IEnumerator 
    LOC_Enum = loclist.GetEnumerator 
    Do While LOC_Enum.MoveNext 
     locstr = (LOC_Enum.Current) 
    Loop 
    Do While (res_numer.MoveNext) 
     str = (res_numer.Current) 
    Loop 

    For Each str In loclist 
     If Not loclist.Contains(str) = True Then 
      My.Computer.Network.DownloadFile("ftp://www.ahpg.zxq.net/ftpfiles/" & str.ToString, _ 
              "C:/Program Files/Business Elements/Recent Files/" & str.ToString, "eg", "eg") 
      MessageBox.Show("Done ") 
     End If 
    Next 

End Sub 
+0

해결책이있는 사람이 있습니까? – Kraxed

+0

어제 제 코드를 편집했습니다. 누구든지 내 문제를 파악할 수 있습니까? – Kraxed

+0

그러면 오류는 무엇입니까? 로그가 있습니까? 귀하의 질문에 그것을 포함하십시오. –

답변

1

괜찮을 것 같네요 있도록 모든 세부 사항을 알고 있다고 가정 다운로드합니다. 여기 요 :

' Your instance of FTPClient 
    Dim ftp As New FTPclient("ftp://www.ahpg.zxq.net", "eg", "eg") 

    ' The path to destination folder (Local directory) 
    Dim localDir As String = "C:/Program Files/Business Elements/Recent Files/" 

    ' Lists all the file in the given directory of FTP server 
    For Each file As FTPfileInfo In ftp.ListDirectoryDetail("/").GetFiles 

     Try 
      ftp.Download(file, localDir & file.Filename) 

      ' The FTPClient class throws exception if the 
      ' file already exists in destination directory 
     Catch e As ApplicationException 
      Console.WriteLine(e.Message) 
     End Try 
    Next file 

주 1을 : 나는 CodeProject에서 FTPClient 클래스를 다운로드하지만 거의 당신이 질문에 제공 한 것과 동일합니다.

참고 2 : 대상 폴더에 파일이있는 경우 FTPClient 자체가 예외를 발생시킵니다. 따라서 파일 비교를 신경 쓰지 않아도됩니다.

주 3 : locadDir 문자열의 끝에서 후행 슬래시을 알 수 있습니다. 이 파일이 없으면 비즈니스 요소 폴더로 파일이 다운로드됩니다.

+0

은 완벽합니다. 이미 존재했다면 예외를 만들지는조차 모릅니다. 고맙습니다. – Kraxed

+0

상위 디렉토리에 하위 디렉토리가있는 경우 어떻게해야합니까? – Reaper211

0

는 FTP에서 파일이 이미있는 경우의 확인을 IsExistedInLocal을 부르 자, 서브 방법을 쓰기 당신의 지역 여부. 그렇다면 무시하고 다음 단계로 넘어갑니다. 그렇지 않은 경우, 믿을수가 의사 코드는 내가 당신을 위해 작동하는 경우 조금 더 쉽게

for each FTP_file in FTP_FilesList 
    if not IsExistedInLocal(FTP_file) then 
    download the file to local 
    end if 
next 
+0

IsExistedInLocal 클래스는 어떻게 만들 수 있습니까[email protected] – Kraxed

0

for 루프에서 목록의 각 항목을 가져 와서 같은 목록에 해당 요소가 없는지 확인하고 있습니다. if 조건은 결코 사실이 아니며 DownloadFile 문에 도달하지 않습니다.

For Each str In loclist 
    If Not loclist.Contains(str) = True Then 
     My.Computer.Network.DownloadFile("ftp://www.ahpg.zxq.net/ftpfiles/" & str.ToString, _ 
             "C:/Program Files/Business Elements/Recent Files/" & str.ToString, "eg", "eg") 
     MessageBox.Show("Done ") 
    End If 
Next 
+0

어떻게 할 것인가에 대한 예를 들어 주시겠습니까? 나는 조금 붙어있다. – Kraxed

관련 문제