PB.Ex FTP (Windows)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: PB.Ex FTP (Windows)

Post by RSBasic »

It's the current version. I forgot to change the version comment. :oops:
Image
Image
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: PB.Ex FTP (Windows)

Post by Joris »

RSBasic, already a thanks for this.
I will need it probably one of these as you noticed.
Still have a lot to figure out.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: PB.Ex FTP (Windows)

Post by the.weavster »

RSBasic wrote:PureBasic can neither SFTP (SSH File Transfer Protocol) nor FTPS (FTP over SSL/TLS). With this library this is possible.
Thank you, RSBasic :!:
This library was a big help for me today :D
Amundo
Enthusiast
Enthusiast
Posts: 191
Joined: Thu Feb 16, 2006 1:41 am
Location: New Zealand

Re: PB.Ex FTP (Windows)

Post by Amundo »

Better late than never, but thanks heaps RSBasic, this is exactly what I need right now.

Now all I have to do is download it through our (work) ISP who flags your site as having a malicious reputation....grrrrrrrrrrrrrrrr!!!!!!!!!!!!!!!

Regards,
Amundo
Win8.1, PB5.x, okayish CPU, onboard video card, fuzzy monitor (or is that my eyesight?)
"When the facts change, I change my mind" - John Maynard Keynes
mikejs
Enthusiast
Enthusiast
Posts: 160
Joined: Thu Oct 21, 2010 9:46 pm

Re: PB.Ex FTP (Windows)

Post by mikejs »

Hi,

I'm trying to use this library in something, but am running into a problem where the first connection to a server works, but later attempts to reconnect to that server fail, and this failure continues until logoff (i.e. quitting and restarting the program doesn't help)

Specifically, I have a process that will periodically have data to upload via FTPS. For what this process needs to do, it doesn't need to look at what's in the FTP server folder, so is not using ExamineFTPDirectoryEx(), but going straight to uploading its files. This is partly because it doesn't need to know what's there, but also because the folder its uploading to may have a high filecount, so enumerating the contents would be slow.

Another process is looking at the upload location (not by FTP) to process the files that appear there. To avoid file locking issues between the upload and processing systems, I upload as a temporary file name and then rename once the upload completes. As a precaution, I attempt to delete any existing file of the intended final or temporary name before uploading. (This is probably not relevant to the problem, but more of an explanation for why the code below is doing what it does.)

So, the code goes something like this:

Code: Select all

errorout$=Space(128)
ftphnd=OpenFTPEx(#PB_Any, #PBEx_FTP_Protocol_FTPS_Explicit, server$, 21, user$, pass$, #PB_UTF8, @errorout$)
If ftphnd
  Debug "Got ftp handle: "+Str(ftphnd)
  
  ; Delete any existing real or temp file. Probably none, so ignore errors.
  DeleteFTPFileEx(ftphnd, desttmp$, @errorout$)
  DeleteFTPFileEx(ftphnd, destfinal$, @errorout$)
  
  ; Upload to temp file then rename.
  errorout$=Space(128)
  If SendFTPFileEx(ftphnd, src$, desttmp$, #False, @errorout$)
    Debug "ftp upload successful, renaming destination."
    errorout$=Space(128)
    If RenameFTPFileEx(ftphnd, desttmp$, destfinal$, @errorout$)
      Debug "ftp rename successful, deleting local file"
      DeleteFile(src$)
    Else
      Debug "Unable to rename file"+desttmp$+" : "+Trim(errorout$)
    EndIf
  Else
    Debug "Unable to upload file: "+src$+" : "+Trim(errorout$)
  EndIf
  
  Debug "Closing FTP connection"
  errorout$=Space(128)
  result=CloseFTPEx(ftphnd, @errorout$)
  Debug "Result: "+Str(result)+" : "+Trim(errorout$)
  ftphnd=0
Else
  Debug "Failed to connect to FTP : "+Trim(errorout$)
EndIf
This all works for the first upload attempt, the file(s) are uploaded correctly and all is well. CloseFTPEx() returns success.

Subsequent attempts result in OpenFTPEx() returning 0 and setting errorout$ to "Error: Timed out trying to read data from the socket stream!". (I.e. this is reported by the "Failed to connect" line at the end.)

All subsequent attempts to connect fail with this error. Closing the PB application and restarting it doesn't fix it (!) (meaning whatever is stuck is not a PB handle but something more fundamental).

Logging off and back on again clears it (but again, for only one upload). Rebooting also fixes it for one upload.

This looks like something from the first upload is not being closed properly, but I don't see anything I'm missing there. I have a CloseFTPEx() that corresponds with the OpenFTPEx(), am not using IsAsynchron anywhere, and there are no directories I need to finish.

Underlying OS is Win10 1809 (build 17763) 64bit. FTP server is XLightFTPd on Windows. Files being transferred are relatively small (few KB, typically), and are UTF8 text.

Googling the error message leads to pages about the FluentFTP library, such as these:

https://github.com/robinrodricks/FluentFTP/issues/122

https://github.com/robinrodricks/FluentFTP/issues/124

But the suggestions there don't seem to offer anything I can try from within PB.

Any ideas?
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: PB.Ex FTP (Windows)

Post by Bisonte »

@mikejs:

I make a project with this dll and I use SFTP Connection. I find out that #PB_Any sometimes work and sometimes not.
So try out if your connections will work if you are using a fixed ID for that....

e.g. OpenFTPEx(1, Server......
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
mrv2k
User
User
Posts: 51
Joined: Fri Jan 20, 2012 3:40 pm
Location: SE England
Contact:

Re: PB.Ex FTP (Windows)

Post by mrv2k »

Hi

Thanks for the great DLL files but I have a bit of an issue. I'm writing a downloader for Amiga WHDLoad files and if I try to download the following file , ReceiveFTPFileEx give me nothing.

100MostRememberedGamesOnThe64_v1.01_PerhåkanSundell&RonBirk.lha

I'm pretty sure it's the 'å' that is doing it. Possibly it's a Ascii -> Unicode problem. I've set up OpenFTPEx as #PB_Ascii as the Turran FTP server requires it, though UTF-8 will connect and give the same error. Unicode just gives me an error.

These are the settings I'm using...

Protocol: #PBEx_FTP_Protocol_FTP (Doesn't work with anything else!)
Server: grandis.nu
Port: 21
User: ftp
Pass: amiga
Connection: Passive
Folder: /Retroplay WHDLoad Packs/Commodore_Amiga_-_WHDLoad_-_Demos/0

I have tried the native Purebasic library but some of the guys who tried to download files got no response from the FTP. These DLL's work the best.
GogaII
User
User
Posts: 27
Joined: Sun Nov 15, 2020 10:03 am

Re: PB.Ex FTP (Windows)

Post by GogaII »

this DLL works fine as FTP but doesn't work as FTPS when I try to connect to my FileZilla server :(
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB.Ex FTP (Windows)

Post by infratec »

You can try libcurl with external dll where ftps is included.

viewtopic.php?t=76313
GogaII
User
User
Posts: 27
Joined: Sun Nov 15, 2020 10:03 am

Re: PB.Ex FTP (Windows)

Post by GogaII »

Thanks, but could you update your link of your zip-file, because none of the links is working? I'm not a professional, so I need examples :oops:
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB.Ex FTP (Windows)

Post by infratec »

Ups ...

I decided to make an own topic about my libcurl.pbi where I put one link at a central place:

viewtopic.php?p=591235
GogaII
User
User
Posts: 27
Joined: Sun Nov 15, 2020 10:03 am

Re: PB.Ex FTP (Windows)

Post by GogaII »

Thanks a lot)
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: PB.Ex FTP (Windows)

Post by RSBasic »

mrv2k wrote: Sat Dec 25, 2021 3:40 pm Hi

Thanks for the great DLL files but I have a bit of an issue. I'm writing a downloader for Amiga WHDLoad files and if I try to download the following file , ReceiveFTPFileEx give me nothing.

100MostRememberedGamesOnThe64_v1.01_PerhåkanSundell&RonBirk.lha

I'm pretty sure it's the 'å' that is doing it. Possibly it's a Ascii -> Unicode problem. I've set up OpenFTPEx as #PB_Ascii as the Turran FTP server requires it, though UTF-8 will connect and give the same error. Unicode just gives me an error.
Hello

I tried to download a file with this filename from my FTP server. It works without error.

Code: Select all

Debug ReceiveFTPFileEx(1, "100MostRememberedGamesOnThe64_v1.01_PerhåkanSundell&RonBirk.lha", "D:\100MostRememberedGamesOnThe64_v1.01_PerhåkanSundell&RonBirk.lha", 0, @ErrorOutput$)
  Debug ErrorOutput$
The content of the downloaded file is also correct.
I can't confirm.
Image
Image
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: PB.Ex FTP (Windows)

Post by RSBasic »

mikejs wrote: Mon Jun 08, 2020 3:10 pm I'm trying to use this library in something, but am running into a problem where the first connection to a server works, but later attempts to reconnect to that server fail, and this failure continues until logoff (i.e. quitting and restarting the program doesn't help)

Specifically, I have a process that will periodically have data to upload via FTPS. For what this process needs to do, it doesn't need to look at what's in the FTP server folder, so is not using ExamineFTPDirectoryEx(), but going straight to uploading its files. This is partly because it doesn't need to know what's there, but also because the folder its uploading to may have a high filecount, so enumerating the contents would be slow.

Another process is looking at the upload location (not by FTP) to process the files that appear there. To avoid file locking issues between the upload and processing systems, I upload as a temporary file name and then rename once the upload completes. As a precaution, I attempt to delete any existing file of the intended final or temporary name before uploading. (This is probably not relevant to the problem, but more of an explanation for why the code below is doing what it does.)

This all works for the first upload attempt, the file(s) are uploaded correctly and all is well. CloseFTPEx() returns success.

Subsequent attempts result in OpenFTPEx() returning 0 and setting errorout$ to "Error: Timed out trying to read data from the socket stream!". (I.e. this is reported by the "Failed to connect" line at the end.)

All subsequent attempts to connect fail with this error. Closing the PB application and restarting it doesn't fix it (!) (meaning whatever is stuck is not a PB handle but something more fundamental).

Logging off and back on again clears it (but again, for only one upload). Rebooting also fixes it for one upload.

This looks like something from the first upload is not being closed properly, but I don't see anything I'm missing there. I have a CloseFTPEx() that corresponds with the OpenFTPEx(), am not using IsAsynchron anywhere, and there are no directories I need to finish.
Hello

I can't confirm.
I tested with FTP and with SFTP.
Here it works:
[20:44:11] Got ftp handle: 0
[20:44:11] ftp upload successful, renaming destination.
[20:44:11] ftp rename successful, deleting local file
[20:44:11] Closing FTP connection
[20:44:11] Result: 1 :
I tested several times. He can delete, upload and rename the file.

I used the following code (based on your code):

Code: Select all

[...]

Define ErrorOutput$ = Space(128)
Define ftphnd
Define desttmp$ = "NtlmTest.temp"
Define src$ = "D:\NtlmTest.cs"
Define destfinal$ = "NtlmTest.cs"
Define result

ftphnd = OpenFTPEx(#PB_Any, #PBEx_FTP_Protocol_FTP, "...........", 21, ".............", ".................", #PB_UTF8, @ErrorOutput$)
If ftphnd > -1
  Debug "Got ftp handle: "+Str(ftphnd)
  
  ; Delete any existing real or temp file. Probably none, so ignore errors.
  DeleteFTPFileEx(ftphnd, desttmp$, @ErrorOutput$)
  DeleteFTPFileEx(ftphnd, destfinal$, @ErrorOutput$)
  
  ; Upload to temp file then rename.
  ErrorOutput$=Space(128)
  If SendFTPFileEx(ftphnd, src$, desttmp$, #False, @ErrorOutput$)
    Debug "ftp upload successful, renaming destination."
    ErrorOutput$=Space(128)
    If RenameFTPFileEx(ftphnd, desttmp$, destfinal$, @ErrorOutput$)
      Debug "ftp rename successful, deleting local file"
      ;DeleteFile(src$)
    Else
      Debug "Unable to rename file"+desttmp$+" : "+Trim(ErrorOutput$)
    EndIf
  Else
    Debug "Unable to upload file: "+src$+" : "+Trim(ErrorOutput$)
  EndIf
  
  Debug "Closing FTP connection"
  ErrorOutput$=Space(128)
  result=CloseFTPEx(ftphnd, @ErrorOutput$)
  Debug "Result: "+Str(result)+" : "+Trim(ErrorOutput$)
  ftphnd=0
  
  CloseFTPEx(ftphnd, @ErrorOutput$)
Else
  Debug ErrorOutput$
EndIf

CloseLibrary(PBEx_FTP)
In my C# project of the DLL file closing the connection looks like this:

Code: Select all

public static int CloseFTPEx(int ID, System.IntPtr ErrorOutput) {
    [...]
    
    PBIDObject[ID].FTPConnection.Disconnect();
    PBIDObject[ID].FTPConnection.Dispose();
    PBIDObject[ID].FTPConnection = null;
    PBIDObject[ID].Files.Clear();
    
    [...]
}
I don't know why it doesn't work for you.
Image
Image
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: PB.Ex FTP (Windows)

Post by RSBasic »

PB.Ex FTP 1.0.6.0 has been released.

Changelog:
  • Updated: .NET Framework 4 > .NET Framework 4.7.2
  • Improved: FTPDirectoryEntrySizeEx(): x86 version: Size of files larger than 4 GB can be read.
  • Added: AbortFTPFileEx()

CalamityJames wrote: Fri Oct 08, 2021 4:06 pm The function FTPDirectoryEntrySizeEx seems to return an integer which is not really enough for some recent video files (in 32bit). By a bit of peeking and poking with a Purebasic quad it is possible to treat the returned integer as unsigned which means the maximum files size returned correctly is 4294967295. There are still video files bigger than this, though.
Done
Image
Image
Post Reply