• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 778
  • Last Modified:

Problem with FTP using VB.Net

I am using the FTP code found here:

http://www.codeproject.com/vb/net/FtpClient.asp

I am trying to download files from an FTP and store them on a network drive.  I can use the following code successfully to download a single file:

Dim myFtp As New FTPclient("192.168.1.200", "jhaft", "alp123ha")
        Dim fullList As FTPdirectory = myFtp.ListDirectoryDetail("")
        Dim filesOnly As FTPdirectory = fullList.GetFiles() 'fullList.GetFiles()
        myFtp.Download("/test1.xls", "M:\Corporate\Finance\Corporate Finance\FDM4 Reports\To Process" + "\test1.xls")


But what I really need to is download every .XLS file.  So, I'm trying this but it doesnt work:

Sub Main()
        Dim myFtp As New FTPclient("192.168.1.200", "jhaft", "password")
        Dim fullList As FTPdirectory = myFtp.ListDirectoryDetail("")
        Dim filesOnly As FTPdirectory = fullList.GetFiles() '
        For Each file As FTPfileInfo In myFtp.ListDirectoryDetail.GetFiles
            ' If Not file.Filename Like "*xls*" Then GoTo SkipFile
            myFtp.Download(file.Filename, "M:\Corporate\Finance\Corporate Finance\FDM4 Reports\To Process\" + file.Filename)
            'SkipFile:
        Next file

The problem has to do with the was I am setting the filename...i get a "PathTooLongException" and when I look at the filename I am setting it comes back as:

M:\Corporate\Finance\Corporate Finance\FDM4 Reports\To Process\.profile-rw-r-----   1 jhaft    staff         13824 Jul 27 14:46 test2.xls-rw-r-----   1 jhaft    staff          1317 Jul 27 12:04 test3.xls-rw-r-----   1 jhaft    staff         13824 Jul 27 14:46 test4.xls

What am I doing wrong here?

Or, is there another way I could do this?


0
collages
Asked:
collages
  • 2
1 Solution
 
Babycorn-StarfishCommented:
Can you not specify the directory you start in and thus reduce the path length to just the filename part?
0
 
Babycorn-StarfishCommented:
like with the example code:

For Each file As FtpFileInfo In myFtp.GetDirectoryDetail("/pub/").GetFiles
    myFtp.Download(file, "C:\" & file.Filename)
Next file

he specifies /pub
0
 
Bob LearnedCommented:
Are you working with 2005 or 2003?

Bob
0
 
collagesAuthor Commented:
2005 Express, but I actually posted this on CodeProject and the guy who wrote the library is helping me.  I dont want to have people doing double work on this, so dont feel the need to post here as of yet.  If he cant help me (I assume he can since he wrote the library), I'll post back here.

Of course if you want to help that would be great  :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now