Page 1 of 2
Vs 4.20 Beta 1 FTP library - Help needed
Posted: Thu Jan 24, 2008 12:03 am
by TerryHough
I am anxious to use the FTP library.
But, so far I haven't been able to get anything to work.
Can anybody show me a working example of sending and receiving a file?
TIA
Terry
ftp Library
Posted: Fri Jan 25, 2008 6:09 am
by afriend
TerryHough, I am surprised none of the gurus on the site have responded by now. These guys are really responsive and have willing given a wealth of knowledge. The following code does work. I wrote it to send a file to one of my servers and then to retrieve the file and lastly to delete the file from the server. Note the retrieved file has a differrent name. This last aspect is to verify what went and was received was OK.
Be aware, I have changed the ip addresses etc for this post. The parameters are not real - I hope. Substitute your own.
I think the PureBasic team have done well with this release, but there were/are some issues with the text description of the library. I have corrected them at the front of the code and when run they all appear to perform as expected.
I trust I have been of assistance to you in this matter.
29 Jan 2008 - corrected function -
From
ExamineFTPDirectory(#Ftp. Directory$)
To
ExamineFTPDirectory(#Ftp)
Code: Select all
;***************************************************************
;Example by P Dixon ala Afriend
;25 Jan 2008
;***************************************************************
;
;FTP Commands available - note original text file had "String" or "StringString" or StringStringString"
;appended To some of the commands. I believe these were in error but stand to be corrected:
;
;CloseFTP(#Ftp) - Close the specified client connection And send a notification To the server.
;CreateFTPDirectory(#Ftp ,Directory$) - Create a new directory on the FTP server.
;DeleteFTPDirectory(#Ftp, Directory$) - Delete a directory on the FTP server.
;DeleteFTPFile(#Ftp ,Filename$) - Delete a file on the FTP server.
;ExamineFTPDirectory(#Ftp) - Examine the current directory on the FTP server.
;GetFTPDirectory(#Ftp) - Return the current directory.
;FinishFTPDirectory (#Ftp) - Free the Data allocated With ExamineFTPDirectory.
;FTPDirectoryEntryAttributes (#Ftp) - Return the attributes of the current entry in the last FTP listing.
;FTPDirectoryEntryDate (#Ftp) - Return the modified date of the current entry in the last FTP listing.
;FTPDirectoryEntryName (#Ftp) - Return the name of the current entry in the last FTP listing.
;FTPDirectoryEntrySize (#Ftp) - Return the size of the current entry in the last FTP listing.
;FTPDirectoryEntryType (#Ftp) - Return the type of the current entry in the last FTP listing.
;FTPProgress(#Ftp) - Return the progress on the current transfer.
;IsFTP(#Ftp) - Tests If the given '#Ftp' is an initialized FTP object.
;NextFTPDirectoryEntry(#Ftp) - Go To the Next FTP directory entry
;OpenFTP(#Ftp ,ServerName$, User$, Password$ [Passive [Port]]) - Try To open a connection on the specified server.
;ReceiveFTPFile(#Ftp, RemoteFilename$, Filename$ [Asynchronous]) - Receive a file from a FTP Server.
;RenameFTPFile(#Ftp, Filename, $NewFilename$) - Rename Or move a file on the FTP server.
;SendFTPFile(#Ftp, Filename$, RemoteFilename$ [Asynchronous]) - Send a file To a FTP Server.
;SetFTPDirectory(#Ftp, Directory$) - Change the current directory.
;
;Using the above modified commands works quite well.
;
;
;Host parameters fictional for exercise - substitute your own legitimate parameters
ipadd.s = "10.300.20.1"
computer.s = "root"
password.s = "goodgoing"
;First initialise the network
InitNetwork()
OpenConsole()
;now open ftp
If OpenFTP(0, ipadd.s, computer.s, password.s, 0)
;At this point ftp is open - now send a file from this computer to the host
Result = SendFTPFile(0, "d:\Test.txt", "testtext", 1)
;follow file transfer progress until end of failure
Repeat
Debug FTPProgress(0)
Delay(300)
Until FTPProgress(0) = -3 Or FTPProgress(0) = -2
;As near as I can make out FTPProgress(0)
;-1 = in progress transmit file
;-2 = file not found or some error
;-3 = file transmited/received - function complete successful?
;so you could put better traps/filters in but this is just a demo
;give user an indication ftp finished
Debug "finished - transmitting file" + " FTPflg = " + Str(FTPProgress(0))
;Now get file from host and store on local computer to ensure file transfer OK
Result = ReceiveFTPFile(0, "testtext", "d:\TestReturn.txt", 0)
Repeat
Debug FTPProgress(0)
Delay(300)
Until FTPProgress(0) = -3 Or FTPProgress(0) = -2
Debug "finished - receieved file in directory" + " FTPflg = " + Str(FTPProgress(0))
DeleteFTPFile(0 ,"testtext")
CloseFTP(0)
Else
;if ftp did not open give a failed indication
Debug "Failed"
EndIf
Posted: Fri Jan 25, 2008 4:41 pm
by TerryHough
@afriend
Thanks for your reply. I, too, was a bit surprised one of the gurus hadn't answered.
Could be that they think I already know. If you search, you will see I have been a frequent contributor of FTP related code. For example, search for FTPXCHG or FTP Library.
However, I have not been involved with PB 4.20 in any other way.
I used the example FTP.pb distributed with the Beta 1 version. I got no results with it. After a bit of modifcation, I have been able to "receive" a file, change directory, delete a file. However, I cannot "send" a file successfully.
I own the FTP server, so I can see the actions as they occur at the server. The SendFTPFile is never received at the server.
And, FTPProgress is still a mystery to me.
I didn't want to report this as a bug. Was just going to wait til the documentation was available. But got impatient.
Thanks again for your example. It also fails to send a file to three different FTP servers.
Hopefully this will all work out in future Beta releases and be perfect in the final PB 4.20
Posted: Fri Jan 25, 2008 5:36 pm
by Fluid Byte
TerryHough, I am surprised none of the gurus on the site have responded by now.
Two reasons for this:
1.) The Gurus don't think you are worth any help.
2.) The FTP lib was included just in the last PB update. It's still too new as that many people would have done anything useful with it. Also the documentation is missing since the manual hasn't been updated yet.
Posted: Fri Jan 25, 2008 11:43 pm
by utopiomania
1.) The Gurus don't you think you are worth any help.
I'm embarrased to see this response to a request for help on these forums.
Posted: Sat Jan 26, 2008 12:01 am
by Fluid Byte
utopiomania wrote:I'm embarrased to see this response to a request for help on these forums.
Your lack of humor really baffles me ...

Posted: Sat Jan 26, 2008 12:33 am
by utopiomania
ohh, was that 'humor' ? pardon me...
Posted: Sat Jan 26, 2008 2:10 am
by Fluid Byte
utopiomania wrote:ohh, was that 'humor' ? pardon me...
Please don't pretend to be a smartass. I don't buy it.

Posted: Sat Jan 26, 2008 3:22 am
by DoubleDutch
Posted: Sat Jan 26, 2008 11:45 am
by superadnim
Is it me or the PB manual is being updated manually rather than automatically?, that's .... old.
Posted: Sun Jan 27, 2008 9:30 pm
by utopiomania
Please don't pretend to be a smartass. I don't buy it.
Neither do I

Sorry, had a 'Bad-Hair day'
Posted: Sun Jan 27, 2008 9:53 pm
by Fluid Byte
Good. Now let's get coding again!

Posted: Mon Jan 28, 2008 9:29 pm
by Xombie
I've never been able to get it to receive a file or even list a directory.
For example, this...
Code: Select all
InitNetwork()
If OpenFTP(0, "127.0.0.1", "user", "pass", 0)
Debug "Opened!"
SetFTPDirectory(0, "/live/data")
Debug GetFTPDirectory(0)
If ExamineFTPDirectory(0, "/live/data")
Debug "Examine"
While NextFTPDirectoryEntry(0)
Debug FTPDirectoryEntryName(0)
Wend
FinishFTPDirectory(0)
EndIf
Debug "Done"
CloseFTP(0)
Debug "Closed"
Else
Debug "Failed"
EndIf
Does not work. It shows "Opened!" and then "/live/data" and then "Done" and "Closed". Never gets to the examine stage. Of course, I've changed the address/user/password for this example.
For receive ftp file, if I put it in async transfer, it seems like it's receiving with a -1 event and then a -2. I have no idea what it's doing or what's wrong
I can connect to the ftp with other programs just fine.
ftp commands
Posted: Tue Jan 29, 2008 2:20 am
by afriend
I have shortened my original post to just the send function. The ftp function definetly writes to the server (can't post the image to demonstrate server directory). In addition I can read it back and delete the file from the server as per my previous post.
Xombie - your code has an error in the line that reads -
If ExamineFTPDirectory(0, "/live/data")
should be
If ExamineFTPDirectory(0)
then all works OK at my end
Code: Select all
;***************************************************************
;Example by P Dixon ala Afriend
;29 Jan 2008
;***************************************************************
;Host parameters fictional for exercise - substitute your own legitimate parameters
ipadd.s = "10.300.20.1"
computer.s = "root"
password.s = "goodgoing"
InitNetwork()
OpenConsole()
If OpenFTP(0, ipadd.s, computer.s, password.s, 0)
Result = SendFTPFile(0, "d:\Test.txt", "testtext", 1)
Repeat
Debug FTPProgress(0)
Delay(300)
Until FTPProgress(0) = -3 Or FTPProgress(0) = -2
Debug "finished - transmitting file" + " FTPflg = " + Str(FTPProgress(0))
Else
Debug "Failed"
EndIf
End
Posted: Tue Jan 29, 2008 3:54 pm
by ColBoy
I've tried all of the FTP demos here and I get numerous -1's in the debug window and then it ends with -2, hence FTP does not work.
Colin