Problem with FTP using VB.Net

Posted on 2007-07-30
Last Modified: 2008-01-09
I am using the FTP code found here:

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("", "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("", "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)
        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?

Question by:collages
    LVL 11

    Expert Comment

    Can you not specify the directory you start in and thus reduce the path length to just the filename part?
    LVL 11

    Accepted Solution

    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
    LVL 96

    Expert Comment

    by:Bob Learned
    Are you working with 2005 or 2003?

    LVL 1

    Author Comment

    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  :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now