Dark Basic Pro Tutorial: FTP Functions

James Cloud
When using DarkBasic Professional it is very easy to send data to and from your FTP server. You will learn how to do this by following the simple instructions bellow.

Step One - Connecting to your server

Logically before you can call any FTP function you will first need to connect to an FTP server. You need to define a couple of strings in order to fulfill the requirements for the connection function. Execute this code before attempting to connect to an FTP server.

`Initial settings call before you access the Connect() sub
Username$ = "username" `Replace with your username
Password$ = "password" `Replace with your password
Server$ = "server.com" `Replace with the server you would like to connect to

Now to actually connect to your server create and call the following Sub.

Connect():

`Connect to the desired FTP server using the specified username and password
ftp connect Server$, Username$, Password$

`Check for errors

If Get FTP Failure() = 0
`Connected Successfully
else
`There was an error
EndIf

Return

If you do not know how to call the above function simply use this code: gosub Connect().

Step Two - Getting Files Off the Server

To download a file off the server after you have successfully connected use create a sub called GetFile(). However before you call the GetFile() sub define the following strings as follows:

RemoteFile$ = "filename" `Replace with the name of the file you wish to download
LocalFile$ = "filenameandpath" `Replace with path and filename of the new file

Once you've defined the above you are now free to use this code to make your GetFile() sub.

GetFile():

FTP Get File RemoteFile$, LocalFile$

IF Get FTP Failure() = 0
`The File Was Downloaded Successfully - Place Desired Code Here
else
`There was an error while downloading the file - Place Desired Code Here
EndIf

Return

Step Three - Putting Files Onto the Server

LocalPutFile$ = "filenameandpath"
RemotePutFile$ = "filename

PutFile():

FTP Put File LocalPutFile$, RemotePutFile$

IF Get FTP Failure() = 0
`The File Was Successfully Uploaded - Insert Desired Code Here
else
`There was an error while uploading the file - Insert Desired Code Here
EndIf

Return

Step Four Deleting File on the Server

FileToDel$ = "filename"

DeleteFile():

FTP Delete File FileToDel$

IF Get FTP Failure() = 0
`The File Was Properly Deleted - Place Code Here
else
`There was an error while attempting to delete the file - Place Code Here
EndIf

Return

End

Just a quick note, if you want to change directories in you FTP server simply call this function, "Set FTP Dir()",supplying the directory name as a parameter.

When you wish to disconnect from the FTP server after you have performed your desired functions call, "FTP Disconnect".

This concludes this tutorial on DarkBasic Professional: FTP Functions.

Published by James Cloud

I like to program and do basically anything that has to do with technology and computers.  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.