Re: PB.Ex FTP (Windows)
Posted: Sat Jul 27, 2019 4:35 pm
It's the current version. I forgot to change the version comment. 

http://www.purebasic.com
https://www.purebasic.fr/english/
Thank you, RSBasicRSBasic wrote:PureBasic can neither SFTP (SSH File Transfer Protocol) nor FTPS (FTP over SSL/TLS). With this library this is possible.
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
Hellomrv2k 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.
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$
Hellomikejs 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.
I tested several times. He can delete, upload and rename the file.[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 :
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)
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();
[...]
}
DoneCalamityJames 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.