Simple FTP with BCX! |
|||
I have FTP problems. Not just your everyday "ftp don't work" type problems. I mean problems like, "I use a certain programming language that has no ftp functions built in" type problems. Obviously I'd be an idiot to expect the authors of BCX to make a custom solution just for me. They have much better things to do, like maintaining the greatest Basic to C translator on Earth. So here is my own solution.... trick Jeff into making it for me! :-) Thank you VERY much Jeff Shollenberger. You're a very smart and patient man. -Dr.X- (Fernando Ortiz) One of my programs uses Jeff Shollenberger's FTP library. That program has been running daily for the past 10+ years. |
|||
INSTRUCTIONS:
1. Place the file ( ftp4bcx.inc ) in a convenient directory like your
includes folder or your current project folder.
2. In your bcx program, $include it like you would any other file. (eg: $include "ftp4bcx.inc" )
Connect | FTP_CONNECT (SeverAddress$, UserName$, Password$) |
File Exists | FTP_FILE_EXIST (sFile$) |
Send a file | FTP_SEND_FILE (source$, destination$ [, TRUE | FALSE]) |
Get a file | FTP_GET_FILE (source$, destination$ [, TRUE | FALSE]) |
Rename file or dir | FTP_RENAME (OldName$, NewName$) |
Delete file or dir | FTP_DEL_FILE (NewName$) |
Get current dir | FTP_GET_CUR_DIR ( ) |
Set current dir | FTP_SET_CUR_DIR (FolderName$) |
New Directory | FTP_NEW_DIR (NewFolderName$) |
Delete Directory | FTP_DEL_DIR (FolderName$) |
Enumerate | FTP_ENUM (pattern$, "DIRS" | "FILES" | "ALL") |
Disconnect | FTP_DISCONNECT ( ) |
Establishing a connection to a server |
FTP_CONNECT (SeverAddress$, UserName$,
Password$) Returns TRUE if successful. |
example 1: |
FTP_CONNECT("ftp.bcxgurus.com", "bcxtestuser", "bcxtestuser") |
example 2: |
PRINT
"Conneting to ftp.bcxgurus.com..." IF FTP_CONNECT("ftp.bcxgurus.com", "bcxtestuser", "bcxtestuser") THEN PRINT "Connection Established" ELSE PRINT "Connection Failed!" END IF PAUSE |
Return To Function List |
See if a file exists in the current directory on the server |
FTP_FILE_EXIST(FileName$) Returns TRUE if FileName$ exists, FALSE if not. |
example 1: |
DIM File$ File$ = "SomeFile.txt" PRINT "Checking for file..." IF NOT FTP_FILE_EXIST(File$) THEN PRINT "It's not there!" ELSE PRINT "Found it!" END IF |
example 2: |
IF NOT FTP_FILE_EXIST("update.txt") THEN EXIT |
Return To Function List |
Send a file to the current directory on the server |
FTP_SEND_FILE (source$, destination$ [, TRUE | FALSE]) Returns TRUE if successful. Optional TRUE or FALSE is the overwrite flag. |
example 1: |
FTP_SEND_FILE("MyFile.txt", "NewRemoteFile.txt") |
example 2: |
PRINT "Sending file..." IF NOT FTP_SEND_FILE("example.bas", "example.bas", TRUE) THEN PRINT "Send File Failed!" END IF |
Return To Function List |
Retrieve a file from the current directory on the server |
FTP_GET_FILE (source$, destination$ [, TRUE | FALSE]) Returns TRUE if successful. Optional TRUE or FALSE is the overwrite flag. |
example 1: |
FTP_GET_FILE("RemoteFile.ext", "LocalFile.ext") |
example 2: |
PRINT "Getting file..." IF NOT FTP_GET_FILE("example.bas", "downloaded.bas", FALSE) THEN PRINT "Get File Failed!" END IF |
Return To Function List |
Rename a file or folder on the ftp server |
FTP_RENAME (OldName$, NewName$) Returns TRUE if successful. |
example 1: |
FTP_RENAME("OldName.txt", "NewName.txt") |
example 2: |
'Rename a
folder dim OldFolderName$ dim NewFolderName$ OldFolderName$ = "testfolder" NewFolderName$ = "donetesting" PRINT "Renaming the folder..." IF NOT FTP_RENAME(OldFolderName$, NewFolderName$) THEN PRINT "RENAME FAILED! " & GetLastError() END END IF PRINT "Done! Renamed direcotry from " & OldFolderName$ & " to " & NewFolderName$ |
Return To Function List |
Delete a file or folder from the ftp server |
FTP_DEL_FILE (NewName$) Returns TRUE if successful. |
example 1: |
FTP_DEL_FILE("killme.txt") |
example 2: |
PRINT "Deleting
file..." IF NOT FTP_DEL_FILE("EvilFile.txt") THEN PRINT "Delete File Failed!" END IF PRINT "I totally killed that file!" |
Return To Function List |
Get the current remote directory |
FTP_GET_CUR_DIR( ) Returns the current remote directory. |
example 1: |
PRINT FTP_GET_CUR_DIR() |
example 2: |
directory$ =
FTP_GET_CUR_DIR() PRINT directory$ |
Return To Function List |
Set the current remote directory |
FTP_GET_CUR_DIR (FolderName$ ) Returns the current remote directory. Returns TRUE if successful. |
example 1: |
PRINT FTP_SET_CUR_DIR(FolderName$) |
example 2: |
directory$ =
"MyRemoteFolder" FTP_SET_CUR_DIR(directory$) |
example 2: |
'move up one
directory PRINT "Changing To Previous Directory" IF NOT FTP_SET_CUR_DIR("..") THEN PRINT "Set Dir Failed!" END IF |
Return To Function List |
Create a new remote directory |
FTP_NEW_DIR (NewFolderName$) Creates a new folder on the ftp server. Returns TRUE if successful. |
example 1: |
FTP_NEW_DIR("testfolder") |
example 2: |
PRINT "Making
a new folder..." IF NOT FTP_NEW_DIR("testfolder") THEN PRINT "New Dir Failed!" END END IF |
Return To Function List |
Delete a remote directory |
FTP_DEL_DIR (FolderName$) Deletes a folder on the ftp server. Returns TRUE if successful. |
example 1: |
FTP_DEL_DIR("testfolder") |
example 2: |
PRINT "Deleting
Directory..." IF NOT FTP_DEL_DIR("testfolder") THEN PRINT "Delete Dir Failed!" END IF |
Return To Function List |
Enumerate files / folders |
FTP_ENUM (Pattern$, "DIRS" | "FILES" |
"ALL") |
example 1: |
iRet = FTP_ENUM("*.*", "all") 'print the list of items returned... FOR INTEGER a = 0 TO iRet - 1 PRINT FTP_ENUM_RET$[a] NEXT a |
example 2: |
iRet = FTP_ENUM("*2*",
"DIRS") PRINT "The remote directory contains " & iRet & " folders that have the number two in their names." FOR INTEGER a = 0 TO iRet - 1 PRINT FTP_ENUM_RET$[a] NEXT a |
example 3: |
iRet = FTP_ENUM("*.txt",
"FILES") PRINT "The remote directory contains " & iRet & " text files." FOR INTEGER a = 0 TO iRet - 1 PRINT FTP_ENUM_RET$[a] NEXT a |
Return To Function List |
Disconnect from the ftp server |
FTP_DISCONNECT ( ) Disconnects and releases the wininet ftp session. |
example 1: |
call FTP_DISCONNECT () |
Return To Function List |