Page 2 of 3

Re: PB.Ex FTP (Windows)

Posted: Sat Jul 27, 2019 4:35 pm
by RSBasic
It's the current version. I forgot to change the version comment. :oops:

Re: PB.Ex FTP (Windows)

Posted: Sun Jul 28, 2019 9:03 am
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.

Re: PB.Ex FTP (Windows)

Posted: Tue Sep 10, 2019 4:35 pm
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

Re: PB.Ex FTP (Windows)

Posted: Tue Jan 07, 2020 2:42 am
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

Re: PB.Ex FTP (Windows)

Posted: Mon Jun 08, 2020 3:10 pm
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?

Re: PB.Ex FTP (Windows)

Posted: Mon Oct 26, 2020 7:10 pm
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......

Re: PB.Ex FTP (Windows)

Posted: Sat Dec 25, 2021 3:40 pm
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.

Re: PB.Ex FTP (Windows)

Posted: Sat Nov 12, 2022 12:33 pm
by GogaII
this DLL works fine as FTP but doesn't work as FTPS when I try to connect to my FileZilla server :(

Re: PB.Ex FTP (Windows)

Posted: Sat Nov 12, 2022 2:04 pm
by infratec
You can try libcurl with external dll where ftps is included.

viewtopic.php?t=76313

Re: PB.Ex FTP (Windows)

Posted: Sun Nov 13, 2022 8:29 am
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:

Re: PB.Ex FTP (Windows)

Posted: Sun Nov 13, 2022 11:18 am
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

Re: PB.Ex FTP (Windows)

Posted: Tue Nov 15, 2022 7:30 am
by GogaII
Thanks a lot)

Re: PB.Ex FTP (Windows)

Posted: Thu Aug 31, 2023 7:05 pm
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.

Re: PB.Ex FTP (Windows)

Posted: Thu Aug 31, 2023 7:57 pm
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.

Re: PB.Ex FTP (Windows)

Posted: Thu Aug 31, 2023 9:01 pm
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