Vs 4.20 Beta 1 FTP library - Help needed

Just starting out? Need help? Post your questions and find answers here.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Vs 4.20 Beta 1 FTP library - Help needed

Post 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
afriend
User
User
Posts: 20
Joined: Thu Aug 09, 2007 5:47 am
Location: Melbourne, Australia

ftp Library

Post 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
Last edited by afriend on Tue Jan 29, 2008 2:42 am, edited 2 times in total.
TerryHough
Enthusiast
Enthusiast
Posts: 781
Joined: Fri Apr 25, 2003 6:51 pm
Location: NC, USA
Contact:

Post 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
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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. :twisted:
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.
Last edited by Fluid Byte on Sat Jan 26, 2008 6:12 am, edited 1 time in total.
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post 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.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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 ... Image
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

ohh, was that 'humor' ? pardon me...
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

utopiomania wrote:ohh, was that 'humor' ? pardon me...
Please don't pretend to be a smartass. I don't buy it. Image
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

:lol:
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
superadnim
Enthusiast
Enthusiast
Posts: 480
Joined: Thu Jul 27, 2006 4:06 am

Post by superadnim »

Is it me or the PB manual is being updated manually rather than automatically?, that's .... old.
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

Please don't pretend to be a smartass. I don't buy it.
Neither do I :) Sorry, had a 'Bad-Hair day'
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

Good. Now let's get coding again! Image
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Xombie
Addict
Addict
Posts: 898
Joined: Thu Jul 01, 2004 2:51 am
Location: Tacoma, WA
Contact:

Post 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.
afriend
User
User
Posts: 20
Joined: Thu Aug 09, 2007 5:47 am
Location: Melbourne, Australia

ftp commands

Post 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
ColBoy
Enthusiast
Enthusiast
Posts: 143
Joined: Fri Feb 13, 2004 2:37 pm
Location: Ottawa, Canada
Contact:

Post 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
Colin
Post Reply