FTP list

Discuss any general programming issues here
xabierpayet
Posts: 267
Joined: Fri Feb 24, 2012 9:34 am

FTP list

Post by xabierpayet »

is possible get the ftp list of a drawer?
i can dowload files 1 by 1 (ever knowing the name of the file first) , but i cannot read the ftp contents, a DIR style command or else
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: FTP list

Post by airsoftsoftwair »

Just connect to the FTP server manually using OpenConnection() on port 21, send a list command and grab the results.
xabierpayet
Posts: 267
Joined: Fri Feb 24, 2012 9:34 am

Re: FTP list

Post by xabierpayet »

Andreas please can you post an example?
i only can have this message
220 ftp server ready
and i don´t know how send the list message, i try the hollywood guide examples, with no luck and
i can not understand how this command work

my code

openconnection(1,"xabierpayet.com",21)
senddata(1,"xabierpayet.com,21"..
"list")
a$=receivedata(1,#receiveall)
print(a$)
closeconnection(1)
waitleftmouse

as you can see in my code, i´m not using user or password, when i put the user name and password i
have ever an error, why?, this does´nt work in the same way that downloadfile or uploadfile .
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: FTP list

Post by airsoftsoftwair »

I don't know the FTP protocol by heart. You have to do some reading up on the FTP protocol specification and then interact with the server using SendData() and ReceiveData(). You can simulate this by using a telnet client. Somebody has implemented an FTP handler in Hollywood before, I think it was PEB, maybe he can help you out but it's really not difficult, you just have to become familiar with the FTP protocol.
PEB
Posts: 569
Joined: Sun Feb 21, 2010 1:28 am

Re: FTP list

Post by PEB »

@xabierpayet

FTP uses two channels (a data channel and a control channel). The control channel is the one that you are opening on port 21. Using that control channel, send the PASV command to the server you are contacting; in response you should receive the address and port that the server is opening for your data channel. You then use OpenConnection with that new address and port (received in response to PASV). And finally, you send the LIST command through the control channel, and you should receive the directory list through the data channel.
xabierpayet
Posts: 267
Joined: Fri Feb 24, 2012 9:34 am

Re: FTP list

Post by xabierpayet »

Hello Peb, thanks for your reply but, i don´t can comunicate with my ftp, please check my code:

Code: Select all

openconnection(1,"xabierpayet.com",21)
a$=receivedata(1,#receiveall)
nprint("conexio ",a$)
senddata(1,"PASV" ..
" HTTP/1.0\r\n\r\n")
a$=receivedata(1,#receiveall)
nprint(a$)
senddata(1,"USER XXXXXXX" ..
" HTTP/1.0\r\n\r\n")
a$=receivedata(1,#receiveall)
nprint(a$)
senddata(1,"PASS XXXXXXXX" ..
" HTTP/1.0\r\n\r\n")
a$=receivedata(1,#receiveall)
nprint(a$)
senddata(1,"OPTSUTF8" ..
" HTTP/1.0\r\n\r\n")
a$=receivedata(1,#receiveall)
nprint(a$)
senddata(1,"PWD" ..
" HTTP/1.0\r\n\r\n")
a$=receivedata(1,#receiveall)
nprint(a$)
senddata(1,"LIST" ..
" HTTP/1.0\r\n\r\n")
a$=receivedata(1,#receiveall)
nprint("LIST ",a$)

closeconnection(1)
waitleftmouse
The server answer to the receivedata instruction, but in the moment of send password and user, i have errors in the answer

DebugScreen say...
220 FTP server ready -----ok
530 Please login with user and pass ----ok
500 invalid command: try being more creative ----why?

....

Thanks for the help again, bye
PEB
Posts: 569
Joined: Sun Feb 21, 2010 1:28 am

Re: FTP list

Post by PEB »

Set up a username and password on your server, let me know what those are, and I'll create a small script for you.
xabierpayet
Posts: 267
Joined: Fri Feb 24, 2012 9:34 am

Re: FTP list

Post by xabierpayet »

Hello PEB, i cannot do an ftp, can you make the example with password and user with ####### characters if you want
here in my work is not possible open the ports to try this, we are using an external server
thanks
PEB
Posts: 569
Joined: Sun Feb 21, 2010 1:28 am

Re: FTP list

Post by PEB »

OK, just to give you an example that I can also test on my end. First install FileZilla server on a Windows machine. Next, set up an account with a user name and a password. Now the following code should work for you (once you customize the IP address, user name, and password).

-----
ServerAddress$="192.168.1.134"
UserName$="Test"
Password$="TestPass"

OpenConnection(1, ServerAddress$, 21)
Local data$=ReceiveData(1, #RECEIVELINE)
data$=ReceiveData(1, #RECEIVELINE)
data$=ReceiveData(1, #RECEIVELINE)
SendData(1, "USER "..UserName$.."\r\n")
data$=ReceiveData(1, #RECEIVELINE)
DebugPrint(data$)
SendData(1, "PASS "..Password$.."\r\n")
data$=ReceiveData(1, #RECEIVELINE)
DebugPrint(data$)
SendData(1, "PWD\r\n")
data$=ReceiveData(1, #RECEIVELINE)
DebugPrint(data$)
SendData(1, "TYPE I\r\n")
data$=ReceiveData(1, #RECEIVELINE)
DebugPrint(data$)
SendData(1, "PASV\r\n")
data$=ReceiveData(1, #RECEIVELINE)
DebugPrint(data$)
start=FindStr(data$, "(")+1
end=FindStr(data$, ")")
Temp$=MidStr(data$, start, end-start)
TempTable$, count=SplitStr(Temp$, ",")
TempAddress$=TempTable$[0].."."..TempTable$[1].."."..TempTable$[2].."."..TempTable$[3]
TempPort=ToNumber(TempTable$[4])*256+ToNumber(TempTable$[5])
OpenConnection(2, TempAddress$, TempPort)
SendData(1, "LIST\r\n")
data$=ReceiveData(2, #RECEIVEALL)
DebugPrint(data$)
-----

All that DebugPrint() output is there to show you how the server is responding each time.
xabierpayet
Posts: 267
Joined: Fri Feb 24, 2012 9:34 am

Re: FTP list

Post by xabierpayet »

thanks PEB, work perfectly, very nice example, i love you. xD
Andreas why you don´t put this example in tutorials? a lot of people will find it useful
Post Reply