Page 1 of 2

Help! - Unable to aquire FTP file list!

Posted: Thu Mar 01, 2012 10:23 pm
by keithglong
Hi All,

I am back to playing with FTP and have a problem. I have a shared server with unlimited FTP accounts and have created an account for testing purposes. (I am NOT using the main FTP account for my hosting package.)

Anyway, I am able to upload and download files with no problem. Furthermore, I am also able to make directories and delete directories. The problem I am having is the acquisition of a file list for the FTP account. I have tried both of the following methods, but to no avail:

Code: Select all

libURLSetFTPListCommand "LIST"
get libURLftpCommand("LIST","ftp.mydomain.com","myusername@mydomain.com","mypassword")
answer it
Implementing the above, I keep getting:

425 No Data Connection

Furthermore, I have also tried the following:

Code: Select all

constant FTPHOST = "ftp.mydomain.com"   
put the urlencode of "myusername@mydomain.com" into FTPUSER
put the urlencode of "mypassword" into FTPPASS

 libURLSetFTPListCommand "LIST"
 put url "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST into myVar
 
 answer myVar
But nothing... What am I doing wrong? I thought the problem might be that the username is in the form of an email address (which includes the "@" character), but the other commands work--for example:

Code: Select all

get libURLftpCommand("DELE "&delFile,"ftp.mydomain.com","myusername@mydomain.com","mypassword")

put libURLftpCommand("MKD " &foldername,"ftp.mydomain.com","myusername@mydomain.com","mypassword") into FTPme
Any help would be most appreciated! Thanks!

Sincerely,

- Boo

Re: Help! - Unable to aquire FTP file list!

Posted: Thu Mar 01, 2012 10:42 pm
by sturgis
Can't test at the moment and this stuff is a bit new to me but I have a couple observations.

First. setting the liburlsetftblistcommand to "LIST" just sets a property so that any time the liburl stuff sees an FTP url ending in a slash / it knows what type of directory listing to request. I don't think you can use "LIST" as a command directly with liburlftpcommand directly but as I said, I can't test right this sec. If you wish to use liburlftpcommand to get a listing of files I'd change it to
get liburlftpcommand("ls","yourdomainstuff.com","username@address","yourpassword") and it will actually execute an 'ls' command on the server remotely and give you the results.

If you wish to go the other way, I _think_ you need to end your URL with a slash to get the response you want, otherwise its not looking IN the directory, its looking at the directory itself and can't download the folder so you get resulting weirdness. So try tacking the slash to the end of your ftp url so that liburl knows what you're trying to do.
keithglong wrote:Hi All,

I am back to playing with FTP and have a problem. I have a shared server with unlimited FTP accounts and have created an account for testing purposes. (I am NOT using the main FTP account for my hosting package.)

Anyway, I am able to upload and download files with no problem. Furthermore, I am also able to make directories and delete directories. The problem I am having is the acquisition of a file list for the FTP account. I have tried both of the following methods, but to no avail:

Code: Select all

libURLSetFTPListCommand "LIST"
get libURLftpCommand("LIST","ftp.mydomain.com","myusername@mydomain.com","mypassword")
answer it
Implementing the above, I keep getting:

425 No Data Connection

Furthermore, I have also tried the following:

Code: Select all

constant FTPHOST = "ftp.mydomain.com"   
put the urlencode of "myusername@mydomain.com" into FTPUSER
put the urlencode of "mypassword" into FTPPASS

 libURLSetFTPListCommand "LIST"
 put url "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST into myVar
 
 answer myVar
But nothing... What am I doing wrong? I thought the problem might be that the username is in the form of an email address (which includes the "@" character), but the other commands work--for example:

Code: Select all

get libURLftpCommand("DELE "&delFile,"ftp.mydomain.com","myusername@mydomain.com","mypassword")

put libURLftpCommand("MKD " &foldername,"ftp.mydomain.com","myusername@mydomain.com","mypassword") into FTPme
Any help would be most appreciated! Thanks!

Sincerely,

- Boo

Re: Help! - Unable to aquire FTP file list!

Posted: Thu Mar 01, 2012 11:30 pm
by keithglong
Hi Sturgis,

Thanks for your reply...

I tried:

Code: Select all

get liburlftpcommand("ls","yourdomainstuff.com","username@address","yourpassword")
And got the following message:

500 Unknown command

Also, I tried it the other way with a / but it still does not work:

Code: Select all

constant FTPHOST = "ftp.mydomain.com/"   
put the urlencode of "myusername@mydomain.com" into FTPUSER
put the urlencode of "mypassword" into FTPPASS

libURLSetFTPListCommand "LIST"
put url "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST into myVar

answer myVar
I find this entire situation very odd...

Thanks,

- Boo

Re: Help! - Unable to aquire FTP file list!

Posted: Thu Mar 01, 2012 11:35 pm
by sturgis
Yeah, LIST was correct, its just been way too long since i've done ftp without a gui.

Just for a curiosity test, you might try setting the liburlftpmode to active and see if it makes a difference. /shrug Other than that i'm at a loss.

Re: Help! - Unable to aquire FTP file list!

Posted: Thu Mar 01, 2012 11:47 pm
by mwieder
How about

Code: Select all

put url ("ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST) into myVar

Re: Help! - Unable to aquire FTP file list!

Posted: Fri Mar 02, 2012 12:33 am
by keithglong
Thanks for the suggestions...

@ mwieder: I could have sworn I tried that but tried it again... And it worked! (Thanks!) It could be that my socket was locked up due to all of the testing?

Suggestion: Anyone testing/playing with FTP should use the resetAll command between tests to close any open sockets.

@ sturgis: I tried the libURLSetFTPMode command, but I do not think it made any difference. I bounced back and forth between active and passive. (And please note that when using active mode, any ftp queries activate my antivirus software thinking there is an incoming attack on my PC.) Per the above, I think putting parentheses around the

Code: Select all

liburlftpcommand("ls","yourdomainstuff.com","username@address","yourpassword"
did the trick--after closing a locked socket.

Thing is, although the above seems to be working, I still cannot get the

Code: Select all

 libURLftpCommand("LIST","ftp.mydomain.com","myusername@mydomain.com","mypassword")
to work... Weird.

Thanks for all of the help, and I will continue to play around with it...

Cheers to the most helpful forum community on the Net!

- Boo

Re: Help! - Unable to aquire FTP file list!

Posted: Fri Mar 02, 2012 12:46 am
by mwieder
The parentheses worked because url is a function. What was probably happening before is that the compiler helpfully looked at what you handed it,

Code: Select all

    put url "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST into myVar
and assumed you meant

Code: Select all

    put url ("ftp://") & FTPUSER & ":" & FTPPASS & "@" & FTPHOST into myVar
so explicitly putting the parentheses in place made it unambiguous to the compiler.

... and the

Code: Select all

    libURLftpCommand("LIST","ftp.mydomain.com","myusername@mydomain.com","mypassword")
form won't work at all. The "LIST" command requires the assignment of a secondary port - it could be done by rewriting a special case into the libURLftpCommand handler in the library, but it would be very messy and wouldn't give you any advantages over the url method above.

Re: Help! - Unable to aquire FTP file list!

Posted: Fri Mar 02, 2012 12:55 am
by keithglong
Hello Again,

Regarding your statements about the function, I agree. (And per my previous post, I think I did try the parentheses previously, but I think my socket was locked/jammed.) Using resetAll has made my FTP testing so much more productive...

Thanks again for the excellent information...

Cheers!

- Boo

Re: Help! - Unable to aquire FTP file list!

Posted: Fri Mar 02, 2012 1:45 am
by keithglong
Hi Again,

One more thing...

mwieder wrote:
... and the

Code: Select all

 libURLftpCommand("LIST","ftp.mydomain.com","myusername@mydomain.com","mypassword")
form won't work at all. The "LIST" command requires the assignment of a secondary port - it could be done by rewriting a special case into the libURLftpCommand handler in the library, but it would be very messy and wouldn't give you any advantages over the url method above.
From the LiveCode Dictionary (regarding libURLftpCommand):
The ability to send any FTP command to an FTP server is a powerful function that can enable you to provide full support for all FTP functionality in your application. To use it effectively, you must be familiar with FTP commands and responses and be able to properly construct an FTP command line.
So I suppose "any FTP command to an FTP server" is inaccurate, eh? Bummer.

Thanks,

- Boo

Re: Help! - Unable to aquire FTP file list!

Posted: Fri Mar 02, 2012 1:47 am
by mwieder
Ah, yes... LIST is kind of a special case. Just the way the ftp protocol is designed.

Re: Help! - Unable to aquire FTP file list!

Posted: Fri Mar 02, 2012 1:51 am
by keithglong
Thanks for bringing this to my (our) attention...

Re: Help! - Unable to aquire FTP file list!

Posted: Fri Mar 02, 2012 1:55 am
by mwieder
NP, but it's basically Dave Cragg who brought it to mine a while back.

Re: Help! - Unable to aquire FTP file list!

Posted: Fri Mar 02, 2012 2:33 am
by keithglong
I just added a user note to the LiveCode Dictionary about this. (Hopefully it will make it through.)

Re: Help! - Unable to aquire FTP file list!

Posted: Mon Apr 29, 2013 10:31 am
by derr1ck
Hi,

I'm trying to decipher this ftp list example as I'm trying to do the same thing :D Anyone have a complete working example of how to list an FTP directory, Thanks.

Re: Help! - Unable to aquire FTP file list!

Posted: Mon Apr 29, 2013 1:36 pm
by derr1ck
So far I have this........


constant FTPHOST = "mydomain.com"   
put the urlencode of "myusername@mydomain.com" into FTPUSER
put the urlencode of "mypassword" into FTPPASS

--libURLSetFTPListCommand "LIST"
get liburlftpcommand("ls","mydomain.com","myusername","mypassword")
put url ("ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST) into myVar

answer myVar

The error message I get is "500 LS not understood"