FTP file listing
Posted: Tue Oct 23, 2012 10:15 pm
Hey,
I'm trying to code an app to access a FTP server, upload/download files. Somehow, with PB's FTP commands it seems to be a bit limited, and what I tried (upload/download) did not work properly.
1st: Listing the files.
In PB, you can examine the FTP directory and list the entries. As I want to avoid PB's built in FTP commands, I tried to do it with just network commands. A try to connect on the server and get a list of the entries in the FTP directory:
This --> "150 Opening ASCII mode data connection for /bin/ls". I find it a bit weird as (i think) i have demanded a list of the directory entries. The question is.......what do I do with that thing now and how do I get the list?
2nd:
I tried to upload files WITH PB'S FTP COMMANDS, but it wouldn't work. This is the code:
I can't see the file on the server afterwards.
3rd:
I tried to download files with PB'S FTP COMMANDS, but I didn't get them. my try (
Gadget 20 is a ListViewGadget so I can select entries and click the download button. This doesn't work either.....But I don't understand why.
I hope someone here as more experience with FTP than I and I hope you understand my questions. Thank you in advance
I'm trying to code an app to access a FTP server, upload/download files. Somehow, with PB's FTP commands it seems to be a bit limited, and what I tried (upload/download) did not work properly.
1st: Listing the files.
In PB, you can examine the FTP directory and list the entries. As I want to avoid PB's built in FTP commands, I tried to do it with just network commands. A try to connect on the server and get a list of the entries in the FTP directory:
Code: Select all
Procedure OpenFTPConnection(Servername.s,User.s,Password.s)
Protected.s Reply,Reply2
Protected.i Connection
Connection = OpenNetworkConnection(Servername,21)
*Mem = AllocateMemory (5000)
If ReceiveNetworkData(Connection,*Mem,5000)
Reply = PeekS(*Mem)
If FindString(Reply,"ready") ; CHECK
SendNetworkString(Connection,"USER " + User + #LFCR$)
FreeMemory (*Mem)
Debug Reply
*Mem = AllocateMemory(5000)
If ReceiveNetworkData(Connection,*Mem,5000)
Reply = PeekS(*Mem)
If FindString(Reply,"okay") ;CHECK
SendNetworkString(Connection,"PASS " + Password + #LFCR$)
FreeMemory (*Mem)
Debug Reply
*Mem = AllocateMemory(5000)
If ReceiveNetworkData(Connection,*Mem,5000)
Reply = PeekS(*Mem)
Debug Reply
If FindString(Reply,"proceed") ;Should be logged in now (works)
SendNetworkString(Connection,"NLST " + #LFCR$) ;is this actually how you use NLST?
FreeMemory (*Mem)
Debug Reply
*Mem = AllocateMemory(5000)
If ReceiveNetworkData(Connection,*Mem,5000)
Reply = PeekS(*Mem)
Debug Reply ;150 Opening ASCII mode data connection for /bin/ls <- what's that?
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndProcedure
2nd:
I tried to upload files WITH PB'S FTP COMMANDS, but it wouldn't work. This is the code:
Code: Select all
hi.s = OpenFileRequester ("Select a file..","","*.*",-1)
SendFTPFile(0,hi,GetFilePart(hi),#True)
3rd:
I tried to download files with PB'S FTP COMMANDS, but I didn't get them. my try (
Code: Select all
ExamineFTPDirectory(0)
While NextFTPDirectoryEntry(0)
AddGadgetItem (20,-1,FTPDirectoryEntryName(0))
Wend
For i = 1 To CountGadgetItems(20)
If GetGadgetItemState(20,i)
If ReceiveFTPFile(0,GetGadgetItemText(20,i),SaveFileRequester("Save as..","","*.*",0),#True)
MessageRequester("Success!","Received a file :-)")
Else
MessageRequester("Error!","Could not receive File!")
EndIf
EndIf
Next
I hope someone here as more experience with FTP than I and I hope you understand my questions. Thank you in advance
