'Constants
CONST INTERNET_OPEN_TYPE_DIRECT
= 1
CONST INTERNET_DEFAULT_FTP_PORT
= 21
CONST INTERNET_SERVICE_FTP
= 1
CONST FILE_ATTRIBUTE_ARCHIVE
= &H20 CONST FILE_ATTRIBUTE_COMPRESSED
= &H800 CONST FILE_ATTRIBUTE_DEVICE
= &H40 CONST FILE_ATTRIBUTE_DIRECTORY
= &H10 CONST FILE_ATTRIBUTE_ENCRYPTED
= &H4000 CONST FILE_ATTRIBUTE_HIDDEN
= &H2 CONST FILE_ATTRIBUTE_INTEGRITY_STREAM
= &H8000 CONST FILE_ATTRIBUTE_NORMAL
= &H80 CONST FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
= &H2000 CONST FILE_ATTRIBUTE_NO_SCRUB_DATA
= &H20000 CONST FILE_ATTRIBUTE_OFFLINE
= &H1000 CONST FILE_ATTRIBUTE_READONLY
= &H1 CONST FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS
= &H400000 CONST FILE_ATTRIBUTE_RECALL_ON_OPEN
= &H40000 CONST FILE_ATTRIBUTE_REPARSE_POINT
= &H400 CONST FILE_ATTRIBUTE_SPARSE_FILE
= &H200 CONST FILE_ATTRIBUTE_SYSTEM
= &H4 CONST FILE_ATTRIBUTE_TEMPORARY
= &H100 CONST FILE_ATTRIBUTE_VIRTUAL
= &H10000
'Flags
CONST INTERNET_FLAG_RELOAD
= &H80000000 CONST INTERNET_FLAG_PASSIVE
= &H08000000
CONST FTP_TRANSFER_TYPE_ASCII
= &H00000001 CONST FTP_TRANSFER_TYPE_BINARY
= &H00000002 CONST FTP_TRANSFER_TYPE_UNKNOWN
= &H00000000
CONST MAXDWORD
= &HFFFFFFFF
CONST GENERIC_READ
= &H80000000 CONST GENERIC_WRITE
= &H40000000
ftCreationTime
AS FILETIME
ftLastAccessTime
AS FILETIME
ftLastWriteTime
AS FILETIME
TYPE TIME_DYNAMIC_ZONE_INFORMATION
StandardDate
AS SYSTEMTIME
DaylightDate
AS SYSTEMTIME
DynamicDaylightTimeDisabled
AS _BYTE
'FUNCTION FTPGetFile%% ALIAS FtpGetFileA (BYVAL hConnect AS LONG, BYVAL lpszRemoteFile AS _OFFSET, BYVAL lpszNewFile AS _OFFSET, BYVAL fFailIfExists AS _BYTE, BYVAL dwFlagsAndAttributes AS LONG, BYVAL dwFlags AS LONG, BYVAL dwContext AS _OFFSET)
'FUNCTION FTPPutFile%% ALIAS FtpPutFileA (BYVAL hConnect AS LONG, BYVAL lpszLocalFile AS _OFFSET, BYVAL lpszNewRemoteFile AS _OFFSET, BYVAL dwFlags AS LONG, BYVAL dwContext AS _OFFSET)
CALL FTPConnect
("hostname", "username", "password", INTERNET_DEFAULT_FTP_PORT
)
'a = FTPchdir("Server/Server1/Movies/Bob Hope and Bing Crosby")
a = FTPchdir("Server/Server1/Music")
a = FTPDownload("2Yoon/Harvest Moon/01 24_7.mp3", "C:\Users\Zachary\Music\24_7.mp3")
'a = FTPUpload("C:\Users\Zachary\Music\The Seventh Power\The Power\10 The Power.mp3", "The Seventh Power - The Power.mp3")
'IF a = TRUE THEN PRINT "Uploaded" ELSE PRINT "Upload failed"
'a = FTPmkdir("Test Directory")
'a = FTPdel("The Seventh Power - The Power.mp3")
'CALL FTPdir(".srt")
'CALL FTPdir("")
'PRINT FTPfilelist(".mkv")
IF port
= 0 THEN port
= INTERNET_DEFAULT_FTP_PORT
hInternet = InternetOpen(0, INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0)
PRINT "InternetOpen", GetLastError
hostname
= hostname
+ CHR$(0) username
= username
+ CHR$(0) password
= password
+ CHR$(0) hFtpSession
= InternetConnect
(hInternet
, _OFFSET(hostname
), port
, _OFFSET(username
), _OFFSET(password
), INTERNET_SERVICE_FTP
, INTERNET_FLAG_PASSIVE
, 0) PRINT "InternetConnect", GetLastError
errorlen
= LEN(errorbuffer
) PRINT "Error Info:"; dwError
, MID$(errorbuffer
, 1, errorlen
)
a = InternetCloseHandle(hFtpSession)
a = InternetCloseHandle(hInternet)
IF oldname
<> "" AND newname
<> "" AND hFtpSession
<> 0 THEN oldname
= oldname
+ CHR$(0) newname
= newname
+ CHR$(0) FTPren = a
directory
= directory
+ CHR$(0) a
= FTPRemoveDirectory
(hFtpSession
, _OFFSET(directory
)) FTPrmdir = a
filename
= filename
+ CHR$(0) a
= FTPDeleteFile
(hFtpSession
, _OFFSET(filename
)) FTPdel = a
directory
= directory
+ CHR$(0) a
= FTPCreateDirectory
(hFtpSession
, _OFFSET(directory
)) FTPmkdir = a
IF hFtpSession
= FALSE
OR directory
= "" THEN FTPchdir = FALSE
directory
= directory
+ CHR$(0) a
= FTPSetCurrentDirectory
(hFtpSession
, _OFFSET(directory
)) FTPchdir = FALSE
PRINT "FTPSetCurrentDirectory", GetLastError
errorlen
= LEN(errorbuffer
) PRINT "Error Info:"; dwError
, MID$(errorbuffer
, 1, errorlen
) FTPchdir = a
DIM find
AS WIN32_FIND_DATA
ftpfind
= FTPFindFirstFile
(hFtpSession
, 0, _OFFSET(find
), INTERNET_FLAG_RELOAD
, 0) tempfile
= MID$(find.cFileName
, 1, INSTR(find.cFileName
, CHR$(0)) - 1) filelist
= filelist
+ CHR$(10) + tempfile
a = TRUE
a
= FTPFindNextFile
(ftpfind
, _OFFSET(find
)) tempfile
= MID$(find.cFileName
, 1, INSTR(find.cFileName
, CHR$(0)) - 1) filelist
= filelist
+ CHR$(10) + tempfile
FTPfilelist = filelist
currentdirectory
= SPACE$(MAX_PATH
) lendir
= LEN(currentdirectory
) + 1 DIM systemTime
AS SYSTEMTIME
a
= FTPGetCurrentDirectory
(hFtpSession
, _OFFSET(currentdirectory
), _OFFSET(lendir
)) DIM find
AS WIN32_FIND_DATA
ftpfind
= FTPFindFirstFile
(hFtpSession
, 0, _OFFSET(find
), INTERNET_FLAG_RELOAD
, 0) PRINT "|Directory Listing of ";
MID$(currentdirectory
, 1, lendir
);
"|" PRINT "Last Modified", " Size", , "Name" convertTime
= FileTimeToSystemTime
(_OFFSET(find.ftLastWriteTime
), _OFFSET(systemTime
)) DIM zoneInfo
AS TIME_DYNAMIC_ZONE_INFORMATION
DIM localtime
AS SYSTEMTIME
zone
= GetDynamicTimeZoneInformation
(_OFFSET(zoneInfo
)) year = localtime.wYear
month = localtime.wMonth
day = localtime.wDay
hour = localtime.wHour
minute = localtime.wMinute
timestamp
= timestamp
+ ":" + LTRIM$(STR$(minute
)) timestamp
= timestamp
+ ":0" + LTRIM$(STR$(minute
)) changecolor = 1
IF find.dwFileAttributes
AND FILE_ATTRIBUTE_DIRECTORY
AND filter
= "" THEN dircount = dircount + 1
tempfile
= MID$(find.cFileName
, 1, INSTR(find.cFileName
, CHR$(0)) - 1) filecount = filecount + 1
datasize = (find.nFileSizeLow)
IF datasize
< 0 AND (find.nFileSizeHigh
) > 0 THEN fileSize = datasize + MAXDWORD + (find.nFileSizeHigh * MAXDWORD)
IF (find.nFileSizeHigh
) > 0 THEN fileSize = datasize + (find.nFileSizeHigh * MAXDWORD)
fileSize = datasize + MAXDWORD
fileSize = datasize
filename
= MID$(find.cFileName
, 1, INSTR(find.cFileName
, CHR$(0))) CASE IS < (1024 ^ 3) AND fileSize
>= (1024 ^ 2) PRINT USING "####.## MB";
(fileSize
/ (1024 ^ 2)), CASE IS < (1024 ^ 4) AND fileSize
>= (1024 ^ 3) PRINT USING "####.## GB";
(fileSize
/ (1024 ^ 3)), totalbytes = totalbytes + fileSize
a
= FTPFindNextFile
(ftpfind
, _OFFSET(find
)) convertTime
= FileTimeToSystemTime
(_OFFSET(find.ftLastWriteTime
), _OFFSET(systemTime
)) zone
= GetDynamicTimeZoneInformation
(_OFFSET(zoneInfo
)) year = localtime.wYear
month = localtime.wMonth
day = localtime.wDay
hour = localtime.wHour
minute = localtime.wMinute
timestamp
= timestamp
+ ":" + LTRIM$(STR$(minute
)) timestamp
= timestamp
+ ":0" + LTRIM$(STR$(minute
))
IF find.dwFileAttributes
AND FILE_ATTRIBUTE_DIRECTORY
THEN changecolor = 0
changecolor = 1
dircount = dircount + 1
tempfile
= MID$(find.cFileName
, 1, INSTR(find.cFileName
, CHR$(0)) - 1) changecolor = 0
changecolor = 1
filecount = filecount + 1
datasize = (find.nFileSizeLow)
IF datasize
< 0 AND (find.nFileSizeHigh
) > 0 THEN fileSize = datasize + MAXDWORD + (find.nFileSizeHigh * MAXDWORD)
IF (find.nFileSizeHigh
) > 0 THEN fileSize = datasize + (find.nFileSizeHigh * MAXDWORD) + 1
fileSize = datasize + MAXDWORD
fileSize = datasize
filename
= MID$(find.cFileName
, 1, INSTR(find.cFileName
, CHR$(0))) CASE IS < (1024 ^ 3) AND fileSize
>= (1024 ^ 2) PRINT USING "####.## MB";
(fileSize
/ (1024 ^ 2)), CASE IS < (1024 ^ 4) AND fileSize
>= (1024 ^ 3) PRINT USING "####.## GB";
(fileSize
/ (1024 ^ 3)), totalbytes = totalbytes + fileSize
PRINT filecount
, " file(s)", , ;
PRINT USING "Approx_. ####.## kilobytes";
(totalbytes
/ 1024) CASE IS < (1024 ^ 3) AND totalbytes
>= (1024 ^ 2) PRINT USING "Approx_. ####.## megabytes";
(totalbytes
/ (1024 ^ 2)) CASE IS < (1024 ^ 4) AND totalbytes
>= (1024 ^ 3) PRINT USING "Approx_. ####.## gigabytes";
(totalbytes
/ (1024 ^ 3)) CASE IS < (1024 ^ 5) AND totalbytes
>= (1024 ^ 4) PRINT USING "Approx_. ####.## terabytes";
(totalbytes
/ (1024 ^ 4)) PRINT dircount
, " folder(s)" PRINT "No files could be found matching filter " + CHR$(34) + filter
+ CHR$(34) PRINT "FTPFindFirstFile", GetLastError
errorlen
= LEN(errorbuffer
) PRINT "Error Info:"; dwError
, MID$(errorbuffer
, 1, errorlen
)
IF sourcefile
<> "" AND destfile
<> "" AND hFtpSession
<> 0 THEN 'sourcefile = sourcefile + CHR$(0)
destfile
= destfile
+ CHR$(0) 'a = FTPPutFile(hFtpSession, _OFFSET(sourcefile), _OFFSET(destfile), FTP_TRANSFER_TYPE_BINARY OR INTERNET_FLAG_RELOAD, 0)
hTransfer
= FTPOpenFile
(hFtpSession
, _OFFSET(destfile
), GENERIC_WRITE
, FTP_TRANSFER_TYPE_BINARY
, 0) bytesWritten = bytesWritten + dwWrite
PRINT bytesWritten;
"bytes uploaded of"; filesize
PRINT USING "###.##%";
(bytesWritten
/ filesize
) * 100 FTPUpload = TRUE
bytesWritten = filesize
PRINT bytesWritten;
"bytes uploaded of"; filesize
PRINT USING "###.##%";
(bytesWritten
/ filesize
) * 100 a = InternetCloseHandle(hTransfer)
FTPUpload = FALSE
PRINT "FTPOpenFile", GetLastError
FTPUpload = FALSE
IF sourcefile
<> "" AND destfile
<> "" AND hFtpSession
<> 0 THEN sourcefile
= sourcefile
+ CHR$(0) 'destfile = destfile + CHR$(0)
'a = FTPGetFile(hFtpSession, _OFFSET(sourcefile), _OFFSET(destfile), TRUE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_BINARY, 0)
'FTPDownload = a
hTransfer
= FTPOpenFile
(hFtpSession
, _OFFSET(sourcefile
), GENERIC_READ
, FTP_TRANSFER_TYPE_BINARY
, 0) a
= InternetLockRequestFile
(hTransfer
, _OFFSET(lockhandle
))
FileSizeLow
= FTPGetFileSize
(hTransfer
, _OFFSET(FileSizeHigh
)) datasize = (FileSizeLow)
filesize = datasize + MAXDWORD + (FileSizeHigh * MAXDWORD)
filesize = datasize + (FileSizeHigh * MAXDWORD)
filesize = datasize + MAXDWORD
filesize = datasize
datasize = 0
outputfile
= MID$(buffer
, 1, dwRead
) bytesRead = bytesRead + dwRead
PRINT bytesRead;
"bytes downloaded of"; filesize
PRINT USING "###.##%";
(bytesRead
/ filesize
) * 100 IF bytesRead
= filesize
THEN FTPDownload
= TRUE
ELSE FTPDownload
= FALSE
a = InternetUnlockRequestFile(lockhandle)
a = InternetCloseHandle(hTransfer)
FTPDownload = FALSE
PRINT "FTPOpenFile", GetLastError