PB.Ex FTP (Windows)
Posted: Thu Mar 15, 2018 11:54 pm
Hello,
PureBasic can neither SFTP (SSH File Transfer Protocol) nor FTPS (FTP over SSL/TLS). With this library this is possible. The functions are built in the same style as the FTP library of PureBasic and FTP is also supported.
Functions:
The following copyright texts must be provided:
I would be very pleased about feedbacks, improvement suggestions, error messages or wishes. If you want to support me, you can also donate me a little something. Thanks:)
PureBasic can neither SFTP (SSH File Transfer Protocol) nor FTPS (FTP over SSL/TLS). With this library this is possible. The functions are built in the same style as the FTP library of PureBasic and FTP is also supported.
Functions:
- OpenFTPEx()
- Syntax:
Code: Select all
Result = OpenFTPEx(ID, Protocol, ServerName$, Port, User$, Password$, Charset, @ErrorOutput)
- Description: Establishes a connection to the server.
- Parameter:
- ID: A unique number for the connection. PB_Any can be used to generate the number automatically.
- Protocol: Sets the protocol (FTP, SFTP, FTPS) for the connection: #PBEx_FTP_Protocol_FTP, #PBEx_FTP_Protocol_SFTP, #PBEx_FTP_Protocol_FTPS_Implicit, #PBEx_FTP_Protocol_FTPS_Explicit
- ServerName$: The domain or IP address of the server.
- Port: The port number for the connection.
- User$: The user name for logging in.
- Password$: The password for logging in.
- Charset: Specifies the character set: #PB_UTF8, #PB_Ascii, #PB_Unicode - SFTP uses UTF-8 by default.
- @ErrorOutput: If an error occurred, the error message is stored in the variable. This variable must be reserved with 128 characters before passing. Maximum length of the return is 128 characters including the NULL character. If no error description is to be returned for an error, 0 can be passed instead.
- Return value:
- 1: The process was successful. If #PB_Any is used, the ID is returned.
- Example:
Code: Select all
EnableExplicit Global PBEx_FTP #PBEx_FTP_Version$ = "1.0.6.0" #PBEx_FTP_Protocol_FTP = 1 #PBEx_FTP_Protocol_SFTP = 2 #PBEx_FTP_Protocol_FTPS_Implicit = 3 #PBEx_FTP_Protocol_FTPS_Explicit = 4 CompilerIf #PB_Compiler_Processor = #PB_Processor_x86 PBEx_FTP = OpenLibrary(#PB_Any, "PB.Ex_FTP_x86.dll") CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64 PBEx_FTP = OpenLibrary(#PB_Any, "PB.Ex_FTP_x64.dll") CompilerEndIf If PBEx_FTP Prototype OpenFTPEx(ID, Protocol, ServerName.p-Unicode, Port, User.p-Unicode, Password.p-Unicode, Charset, ErrorOutput) Global OpenFTPEx.OpenFTPEx = GetFunction(PBEx_FTP, "OpenFTPEx") Prototype CloseFTPEx(ID, ErrorOutput) Global CloseFTPEx.CloseFTPEx = GetFunction(PBEx_FTP, "CloseFTPEx") Prototype CheckFTPConnectionEx(ID, ErrorOutput) Global CheckFTPConnectionEx.CheckFTPConnectionEx = GetFunction(PBEx_FTP, "CheckFTPConnectionEx") Prototype IsFTPEx(ID, ErrorOutput) Global IsFTPEx.IsFTPEx = GetFunction(PBEx_FTP, "IsFTPEx") Prototype ExamineFTPDirectoryEx(ID, ErrorOutput) Global ExamineFTPDirectoryEx.ExamineFTPDirectoryEx = GetFunction(PBEx_FTP, "ExamineFTPDirectoryEx") Prototype FinishFTPDirectoryEx(ID, ErrorOutput) Global FinishFTPDirectoryEx.FinishFTPDirectoryEx = GetFunction(PBEx_FTP, "FinishFTPDirectoryEx") Prototype NextFTPDirectoryEntryEx(ID, ErrorOutput) Global NextFTPDirectoryEntryEx.NextFTPDirectoryEntryEx = GetFunction(PBEx_FTP, "NextFTPDirectoryEntryEx") Prototype FTPDirectoryEntryNameEx(ID, Output, ErrorOutput) Global FTPDirectoryEntryNameEx.FTPDirectoryEntryNameEx = GetFunction(PBEx_FTP, "FTPDirectoryEntryNameEx") Prototype.q FTPDirectoryEntrySizeEx(ID, ErrorOutput) Global FTPDirectoryEntrySizeEx.FTPDirectoryEntrySizeEx = GetFunction(PBEx_FTP, "FTPDirectoryEntrySizeEx") Prototype FTPDirectoryEntryTypeEx(ID, ErrorOutput) Global FTPDirectoryEntryTypeEx.FTPDirectoryEntryTypeEx = GetFunction(PBEx_FTP, "FTPDirectoryEntryTypeEx") Prototype FTPDirectoryEntryDateEx(ID, ErrorOutput) Global FTPDirectoryEntryDateEx.FTPDirectoryEntryDateEx = GetFunction(PBEx_FTP, "FTPDirectoryEntryDateEx") Prototype FTPDirectoryEntryAttributesEx(ID, ErrorOutput) Global FTPDirectoryEntryAttributesEx.FTPDirectoryEntryAttributesEx = GetFunction(PBEx_FTP, "FTPDirectoryEntryAttributesEx") Prototype GetFTPDirectoryEx(ID, Output, ErrorOutput) Global GetFTPDirectoryEx.GetFTPDirectoryEx = GetFunction(PBEx_FTP, "GetFTPDirectoryEx") Prototype SetFTPDirectoryEx(ID, DirectoryName.p-Unicode, ErrorOutput) Global SetFTPDirectoryEx.SetFTPDirectoryEx = GetFunction(PBEx_FTP, "SetFTPDirectoryEx") Prototype CreateFTPDirectoryEx(ID, DirectoryName.p-Unicode, ErrorOutput) Global CreateFTPDirectoryEx.CreateFTPDirectoryEx = GetFunction(PBEx_FTP, "CreateFTPDirectoryEx") Prototype DeleteFTPDirectoryEx(ID, DirectoryName.p-Unicode, ErrorOutput) Global DeleteFTPDirectoryEx.DeleteFTPDirectoryEx = GetFunction(PBEx_FTP, "DeleteFTPDirectoryEx") Prototype DeleteFTPFileEx(ID, FileName.p-Unicode, ErrorOutput) Global DeleteFTPFileEx.DeleteFTPFileEx = GetFunction(PBEx_FTP, "DeleteFTPFileEx") Prototype RenameFTPFileEx(ID, FileName.p-Unicode, NewFileName.p-Unicode, ErrorOutput) Global RenameFTPFileEx.RenameFTPFileEx = GetFunction(PBEx_FTP, "RenameFTPFileEx") Prototype ReceiveFTPFileEx(ID, RemoteFileName.p-Unicode, FileName.p-Unicode, IsAsynchron, ErrorOutput) Global ReceiveFTPFileEx.ReceiveFTPFileEx = GetFunction(PBEx_FTP, "ReceiveFTPFileEx") Prototype SendFTPFileEx(ID, FileName.p-Unicode, RemoteFileName.p-Unicode, IsAsynchron, ErrorOutput) Global SendFTPFileEx.SendFTPFileEx = GetFunction(PBEx_FTP, "SendFTPFileEx") Prototype FTPProgressEx(ID, PercentValue, TransferRate, EstimatedTime, ErrorOutput) Global FTPProgressEx.FTPProgressEx = GetFunction(PBEx_FTP, "FTPProgressEx") Prototype AbortFTPFileEx(ID, ErrorOutput) Global AbortFTPFileEx.AbortFTPFileEx = GetFunction(PBEx_FTP, "AbortFTPFileEx") EndIf Define ErrorOutput$ = Space(128) Define FileName$ = Space(#MAX_PATH) Debug "SFTP..." If OpenFTPEx(1, #PBEx_FTP_Protocol_SFTP, "test.rebex.net", 22, "demo", "password", #PB_UTF8, @ErrorOutput$) ;If OpenFTPEx(1, #PBEx_FTP_Protocol_SFTP, "demo.wftpserver.com", 2222, "demo-user", "demo-user", #PB_UTF8, @ErrorOutput$) SetFTPDirectoryEx(1, "pub", @ErrorOutput$) SetFTPDirectoryEx(1, "example", @ErrorOutput$) ;SetFTPDirectoryEx(1, "download", @ErrorOutput$) ;SetFTPDirectoryEx(1, "upload", @ErrorOutput$) If ExamineFTPDirectoryEx(1, @ErrorOutput$) While NextFTPDirectoryEntryEx(1, @ErrorOutput$) FTPDirectoryEntryNameEx(1, @FileName$, @ErrorOutput$) Debug FileName$ Wend EndIf ; Define a ; Define PercentValue = 0 ; Define TransferRate = 0 ; Define EstimatedTime = 0 ; ; ReceiveFTPFileEx(1, "wftpserver-linux-64bit.tar.gz", "D:\wftpserver-linux-64bit.tar.gz", 1, @ErrorOutput$) ; ; For a=1 To 100 ; FTPProgressEx(1, @PercentValue, @TransferRate, @EstimatedTime, @ErrorOutput$) ; Debug PercentValue ; Debug TransferRate ; Debug EstimatedTime ; Debug "--------" ; Delay(100) ; Next ; ; Delay(10000) CloseFTPEx(1, @ErrorOutput$) Else Debug ErrorOutput$ EndIf ; Debug "" ; Debug "FTP..." ; ; If OpenFTPEx(1, #PBEx_FTP_Protocol_FTP, ".........", 21, ".........", ".......", #PB_UTF8, @ErrorOutput$) ; If ExamineFTPDirectoryEx(1, @ErrorOutput$) ; While NextFTPDirectoryEntryEx(1, @ErrorOutput$) ; FTPDirectoryEntryNameEx(1, @FileName$, @ErrorOutput$) ; Debug FileName$ ; Wend ; ; EndIf ; ; CloseFTPEx(1, @ErrorOutput$) ; Else ; Debug ErrorOutput$ ;EndIf Debug "" Debug "FTPS explicit..." If OpenFTPEx(1, #PBEx_FTP_Protocol_FTPS_Explicit, "test.rebex.net", 21, "demo", "password", #PB_UTF8, @ErrorOutput$) If ExamineFTPDirectoryEx(1, @ErrorOutput$) While NextFTPDirectoryEntryEx(1, @ErrorOutput$) FTPDirectoryEntryNameEx(1, @FileName$, @ErrorOutput$) Debug FileName$ Wend EndIf CloseFTPEx(1, @ErrorOutput$) Else Debug ErrorOutput$ EndIf Debug "" Debug "FTPS implicit..." If OpenFTPEx(1, #PBEx_FTP_Protocol_FTPS_Implicit, "test.rebex.net", 990, "demo", "password", #PB_UTF8, @ErrorOutput$) If ExamineFTPDirectoryEx(1, @ErrorOutput$) While NextFTPDirectoryEntryEx(1, @ErrorOutput$) FTPDirectoryEntryNameEx(1, @FileName$, @ErrorOutput$) Debug FileName$ Wend EndIf CloseFTPEx(1, @ErrorOutput$) Else Debug ErrorOutput$ EndIf CloseLibrary(PBEx_FTP)
- Syntax:
- CloseFTPEx()
- Syntax:
Code: Select all
Result = CloseFTPEx(ID, @ErrorOutput)
- Description: Closes the open connection to the server.
- Parameter:
- ID: The number of the connection.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- CheckFTPConnectionEx()
- Syntax:
Code: Select all
Result = CheckFTPConnectionEx(ID, @ErrorOutput)
- Description: Checks if the connection to the server still exists.
- Parameter:
- ID: The number of the connection.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The connection to the server exists.
- Syntax:
- IsFTPEx()
- Syntax:
Code: Select all
Result = IsFTPEx(ID, @ErrorOutput)
- Description: Checks whether the ID was initialized correctly.
- Parameter:
- ID: The number of the connection.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The ID is valid.
- Syntax:
- ExamineFTPDirectoryEx()
- Syntax:
Code: Select all
Result = ExamineFTPDirectoryEx(ID, @ErrorOutput)
- Description: Starts the list from the current directory.
- Parameter:
- ID: The number of the connection.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- FinishFTPDirectoryEx()
- Syntax:
Code: Select all
Result = FinishFTPDirectoryEx(ID, @ErrorOutput)
- Description: Closes the list of the current directory.
- Parameter:
- ID: The number of the connection.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- NextFTPDirectoryEntryEx()
- Syntax:
Code: Select all
Result = NextFTPDirectoryEntryEx(ID, @ErrorOutput)
- Description: The next folder or file is determined.
- Parameter:
- ID: The number of the connection.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: Another folder or file exists.
- Syntax:
- FTPDirectoryEntryNameEx()
- Syntax:
Code: Select all
Result = FTPDirectoryEntryNameEx(ID, @Output, @ErrorOutput)
- Description: The folder or file name is determined.
- Parameter:
- ID: The number of the connection.
- @Output: The folder or file name is stored in the string variable.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- FTPDirectoryEntrySizeEx()
- Syntax:
Code: Select all
Result = FTPDirectoryEntrySizeEx(ID, @ErrorOutput)
- Description: The size of the file is determined.
- Parameter:
- ID: The number of the connection.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- The size of the file is returned.
- Syntax:
- FTPDirectoryEntryTypeEx()
- Syntax:
Code: Select all
Result = FTPDirectoryEntryTypeEx(ID, @ErrorOutput)
- Description: Checks whether the entry is a file or a folder.
- Parameter:
- ID: The number of the connection.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: It's a file. #PB_FTP_File can be used.
- 2: It's a folder. PB_FTP_Directory can be used.
- Syntax:
- FTPDirectoryEntryDateEx()
- Syntax:
Code: Select all
Result = FTPDirectoryEntryDateEx(ID, @ErrorOutput)
- Description: Determines the processing date of the file or folder.
- Parameter:
- ID: The number of the connection.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- The processing date of the file or folder. The value can be used with the Date library.
- Syntax:
- FTPDirectoryEntryAttributesEx()
- Syntax:
Code: Select all
Result = FTPDirectoryEntryAttributesEx(ID, @ErrorOutput)
- Description: Determines the specified attributes of the file or folder.
- Parameter:
- ID: The number of the connection.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- The specified attributes of the file or folder are returned. #PB_FTP_ReadUser, #PB_FTP_WriteUser, #PB_FTP_ExecuteUser, #PB_FTP_ReadGroup, #PB_FTP_WriteGroup, #PB_FTP_ExecuteGroup, #PB_FTP_ReadAll, #PB_FTP_WriteAll and #PB_FTP_ExecuteAll can be used.
- Syntax:
- GetFTPDirectoryEx()
- Syntax:
Code: Select all
Result = GetFTPDirectoryEx(ID, @Output, @ErrorOutput)
- Description: Determines the current path.
- Parameter:
- ID: The number of the connection.
- @Output: The current path is stored in the string variable.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- SetFTPDirectoryEx()
- Syntax:
Code: Select all
Result = SetFTPDirectoryEx(ID, DirectoryName$, @ErrorOutput)
- Description: Opens a subfolder.
- Parameter:
- ID: The number of the connection.
- DirectoryName$: Name of the folder to open.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- CreateFTPDirectoryEx()
- Syntax:
Code: Select all
Result = CreateFTPDirectoryEx(ID, DirectoryName$, @ErrorOutput)
- Description: Creates a new directory.
- Parameter:
- ID: The number of the connection.
- DirectoryName$: Name of the folder to be created.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- DeleteFTPDirectoryEx()
- Syntax:
Code: Select all
Result = DeleteFTPDirectoryEx(ID, DirectoryName$, @ErrorOutput)
- Description: Deletes a directory.
- Parameter:
- ID: The number of the connection.
- DirectoryName$: Name of the folder you want to delete.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- DeleteFTPFileEx()
- Syntax:
Code: Select all
Result = DeleteFTPFileEx(ID, FileName$, @ErrorOutput)
- Description: Deletes a file.
- Parameter:
- ID: The number of the connection.
- FileName$: Name of the file to be deleted.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- RenameFTPFileEx()
- Syntax:
Code: Select all
Result = RenameFTPFileEx(ID, FileName$, NewFileName$, @ErrorOutput)
- Description: Renames a file.
- Parameter:
- ID: The number of the connection.
- FileName$: Name of the file to be renamed.
- NewFileName$: The new name of the file.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- ReceiveFTPFileEx()
- Syntax:
Code: Select all
Result = ReceiveFTPFileEx(ID, RemoteFileName$, FileName$, IsAsynchron, @ErrorOutput)
- Description: Downloads a file.
- Parameter:
- ID: The number of the connection.
- RemoteFileName$: Name of the file to download.
- FileName$: Local destination path.
- IsAsynchron: If 1, then the operation is performed asynchronously. FTPProgressEx() can be used to determine how far the operation has progressed.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- SendFTPFileEx()
- Syntax:
Code: Select all
Result = SendFTPFileEx(ID, FileName$, RemoteFileName$, IsAsynchron, @ErrorOutput)
- Description: Uploads a file.
- Parameter:
- ID: The number of the connection.
- FileName$: Local path of the file to upload.
- RemoteFileName$: Name of the file.
- IsAsynchron: If 1, then the operation is performed asynchronously. FTPProgressEx() can be used to determine how far the operation has progressed.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- SendFTPFileEx()
- Syntax:
Code: Select all
Result = FTPProgressEx(ID, @PercentValue, @TransferRate, @EstimatedTime, @ErrorOutput)
- Description: Determines how far the process is. This function is valid for ReceiveFTPFileEx() or SendFTPFileEx() and when the IsAsynchronous parameter is set to 1.
- Parameter:
- ID: The number of the connection.
- @PercentValue: In this variable the percentage value is stored, how far the process is.
- @TransferRate: The current transmission rate is stored in bytes in this variable.
- @EstimatedTime: The estimated time in seconds is stored in this variable.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- AbortFTPFileEx()
- Syntax:
Code: Select all
Result = AbortFTPFileEx(ID, @ErrorOutput)
- Description: Cancels the current download or upload.
- Parameter:
- ID: The number of the connection.
- @ErrorOutput: If an error occurs, the error message is stored in the string variable.
- Return value:
- 1: The process was successful.
- Syntax:
- Windows XP or higher
- .NET Framework 4.8 or higher
- Unicode activation (standard from PB 5.50)
The following copyright texts must be provided:
Download: https://www.rsbasic.de/downloads/downlo ... Ex_FTP.zipCopyright (c) 2015 Robin Rodricks and FluentFTP Contributors
Copyright © 2019 RSBasic.de
I would be very pleased about feedbacks, improvement suggestions, error messages or wishes. If you want to support me, you can also donate me a little something. Thanks:)