Problem with FTP using VB.Net

Posted on 2007-07-30
Medium Priority
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
  • 2
LVL 11

Expert Comment

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

Accepted Solution

Babycorn-Starfish earned 2000 total points
ID: 19593508
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
ID: 19593654
Are you working with 2005 or 2003?


Author Comment

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

850 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