Chilkat Forum

Technologies => FTP => Topic started by: patwong1998 on November 02, 2017, 02:16:16 AM

Title: FTP2 - How to set Default Remote Directory?
Post by: patwong1998 on November 02, 2017, 02:16:16 AM
I have a FTP need to set "Default Remote Directory" when connecting in Filezilla or the directory for my operation will not be shown.

I try to use ChangeRemoteDir after I get into the root
It give me success but when I list the dir, it failed (suppose there are 2 sub-folder inside)

I searched for "Default Remote Directory" in the API, but seems there is not such setting when connecting to FTP
Title: Re: FTP2 - How to set Default Remote Directory?
Post by: Chilkat on November 02, 2017, 10:08:27 AM
I notice that quite often, a programmer is faced with a problem and doesn't know what to do.  The way to approach any problem, is to first ask "What information is available that will shed light on the cause of the problem?"
  The way to answer this question is to browse the documentation and online examples with that question in mind.

With Chilkat, the answer is always this:  First look at the contents of the LastErrorText property of the object instance for the method call that either failed or didn't behave as expected. 

In the FTP case, there is also the SessionLog, but you'll have to make sure to turn on the KeepSessionLog property to get it.

Finally, if a question is posted with no information other than "it failed", then nobody can really help.  If somebody's kind-hearted, they might suggest posting the contents of the LastErrorText, or ask politely for more information.  But a person with general problem-solving skills would've already found the information.  If that information didn't immediately solve the problem, he/she/... would post the information to make it possible for someone to help...

Title: Re: FTP2 - How to set Default Remote Directory?
Post by: patwong1998 on November 03, 2017, 12:09:35 AM
Thank you for reply
This is my first time asking question here, I will post all the information here.

FYI, I'm not a person just ask question before research:
1. I search for the API reference in your webpage.
2. I googled for the Remote Directory setting
3. I tried combinations of settings to make sure I really connected to the FTP

First of all, below is my code (most copied from your API and examples)
        Dim ftp As New Chilkat.Ftp2
        Dim success As Boolean
        success = ftp.UnlockComponent("OUR PURCHASED KEY")
        If success Then
        End If

        ftp.Passive = False
        ftp.Hostname = xftp
        ftp.Username = ftpuser
        ftp.Password = ftppass
        ftp.Port = 990
        ftp.IdleTimeoutMs = 60000  //GOOGLED that seems someone works after this setting, no luck for me

        ftp.AuthTls = False
        ftp.Ssl = True

        success = ftp.Connect()
        If success Then
            logerror("CONNECTED" & ftp.IsConnected.ToString())
            logerror("Folders:" & ftp.GetDirCount().ToString())
        End If

        logerror("FTPS Channel Established!")
        If True Then
            success = ftp.ChangeRemoteDir("/HKEDI")
            If success Then
                logerror("GET INTO FOLDER")
                logerror("CHG FOLDER FAILED")
            End If
        End If

Information: 0x0 at FTP TEST: UNLOCKED
Information: 0x0 at FTP TEST: CONNECTEDTrue
Information: 0x0 at FTP TEST: Folders:-1
Information: 0x0 at FTP TEST: FTPS Channel Established!
Information: 0x0 at FTP TEST: CHG FOLDER FAILED
Information: 0x0 at FTP TEST: ChilkatLog:
    DllDate: Aug 30 2017
    UnlockPrefix: LOGIST.XXXXXXXX
    Architecture: Little Endian; 32-bit
    Language: .NET 2.0
    VerboseLogging: 0
    dir: /HKEDI
        Not connected to an FTP server.  The connection was previously lost, or it was never established.
Title: Re: FTP2 - How to set Default Remote Directory?
Post by: patwong1998 on November 03, 2017, 12:17:20 AM
In the last attached pictures of FileZilla, you can see FileZilla have a setting on "Default Remote Directory"
if it is set before connection, when connection start, it will auto get into the folder by default (no need to change Directory)
if I do not set it, it will go into a certain root folder which you wont see any folders there, I dont think we can trigger the Change Folder command in Chilkat

So I think the only way is to find out the corresponding command of setting the Default Remote Directory in Chilkat FTP2
After API search and Google, I cannot only find help here.
Title: Re: FTP2 - How to set Default Remote Directory?
Post by: Chilkat on November 06, 2017, 08:49:08 AM
Thanks Patrick,

I wrote this recently in response to another post, and I think it's important here:
(I'll post another response, but please read this first...)

I think some clarification is all that's needed.

The referenced example calls GetDirCount, and then loops over the directory entries, calling GetFilename, GetSize, etc.    The call to GetDirCount fetches (downloads) the directory listing from the FTP server.  The calls to GetFilename, GetSize, etc. are simply returning information from the already-downloaded (cached) directory listing.  Therefore, there is no need for async methods for GetFilename, GetSize, etc. because those methods don't communicate with the FTP server.

It is the GetDirCount method that potentially communicates with the FTP server to download the directory listing, and it has a corresponding GetDirCountAsync method.  In fact, any method in any Chilkat class that communicates over the Internet will automatically have a corresponding Async method.  If no Async method exists, such as for GetFilename, then you'll know that it does not communicate over the Internet.

The GetDirCount method will only fetch a new directory listing if the cached copy is not fresh.  For example, if your application changes the current remote directory, then the cache is no longer fresh and the next call to GetDirCount will fetch the new directory listing.  Also, if you change the ListPattern property, then the next call to GetDirCount will re-fetch.     To clarify further: Let's say the directory cache is not fresh (or has never been downloaded) and you call GetDirCount two times in a row.  The 1st call will fetch the directory listing and return the count.  The 2nd call will find a valid cached directory listing and simply return the count.
Title: Re: FTP2 - How to set Default Remote Directory?
Post by: Chilkat on November 06, 2017, 08:58:13 AM
Here are some comments:

1) The error "Not connected to an FTP server.  The connection was previously lost, or it was never established." indicates that something failed prior to this method call.  You want to find out which prior method call failed (which is where the connection was lost), and then examine the LastErrorText for that method call.

2) The method that likely failed was the call to GetDirCount (which is why I posted above a reply explaining GetDirCount in more detail.)

3) Your code is calling GetDirCount with the assumption that it never fails.  In fact, GetDirCount is the most internally complex call in your code snippet because it is downloading the directory listing from the FTP server, and that requires a separate data connection.  The most likely cause of the failure is that the data connection was blocked by a firewall.  See (

4) I always look to see if the user's code snippet matches the claimed output/log.   For example, your output shows "Information: 0x0 at FTP TEST: FTPS Channel Established!", but I never actually see a line of code in your snippet that produces that output line, so I question whether the code snippet you're showing is what actually produced the given output..

5) I notice this line in your output:  "Information: 0x0 at FTP TEST: Folders:-1"  which clearly shows the call to GetDirCount failed.  That's the problem that needs to be solved.  Any error downstream *after* the connection was already lost is irrelevant..