1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
'------------------------------------------------
'
' Unattended FTP File Download (Sorta)
'
' May 24nd, 2000
'
' Developed under WinNT 4.0 SP5
' WININET.DLL Version 5.00.2314.1003
'
' Target: PB/CC V2.0, PB/DLL V6.0
'
' Public Domain - Your own risk
'
' Notes:
' Will launch the default Internet connection
' dialup as written.
'------------------------------------------------
#Compile Exe
#Dim All
#Include "WIN32API.INC"
'
' Access types
%INTERNET_OPEN_TYPE_PRECONFIG = &H0 ' use registry configuration
%INTERNET_OPEN_TYPE_DIRECT = &H1 ' direct TO net
%INTERNET_OPEN_TYPE_PROXY = &H3 ' via named proxy
%INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = &H4 ' prevent USING java/script/INS
' Service types
%INTERNET_SERVICE_FTP = &H1
%INTERNET_SERVICE_GOPHER = &H2
%INTERNET_SERVICE_HTTP = &H3
' Port definitions
%INTERNET_INVALID_PORT_NUMBER = 0 ' use the protocol-specific DEFAULT
%INTERNET_DEFAULT_FTP_PORT = 21 ' DEFAULT FOR FTP servers
%INTERNET_DEFAULT_GOPHER_PORT = 70 ' " " gopher "
%INTERNET_DEFAULT_HTTP_PORT = 80 ' " " HTTP "
%INTERNET_DEFAULT_HTTPS_PORT = 443 ' " " HTTPS "
%INTERNET_DEFAULT_SOCKS_PORT = 1080 ' DEFAULT FOR SOCKS firewall servers.
%INTERNET_FLAG_PASSIVE = &H8000000 ' used FOR FTP connections
' File transfer methods
%FTP_TRANSFER_TYPE_UNKNOWN = &H0
%FTP_TRANSFER_TYPE_ASCII = &H1
%FTP_TRANSFER_TYPE_BINARY = &H2
'
Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _ ' Failure: %NULL, Success: Handle to the connection
( _
lpszAgent As Long, _ ' Pointer to the calling entity
dwAccessType As Long, _ ' Type of access required
lpszProxyName As Long, _ ' Pointer to the proxy's name
lpszProxyBypass As Long, _ ' Pointer to addresses to bypass proxy
dwFlags As Long _
) As Long ' Unsigned long integer
Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
( _
hInternet As Long, _
lpszServerName As Long, _
nServerPort As Long, _
lpszUserName As Long, _
lpszPassword As Long, _
dwService As Long, _
dwFlags As Long, _
dwContext As Long _
) As Long
Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _
( _
hConnect As Long, _
lpszRemoteFile As Long, _
lpszNewFile As Long, _
fFailIfExists As Long, _
dwFlagsAndAttributes As Long, _
dwFlags As Long, _
dwContext As Long _
) As Long
Declare Function InternetCloseHandle Lib "wininet.dll" Alias "InternetCloseHandle" (hInternet As Long) As Long
Declare Function GetUsernameAndPassword(lpszUserName As Asciiz,lpszPassword As Asciiz) As Long
Declare Function GetPassword() As String
'
' Globals
Global hIOpen As Long
Global hIConnect As Long
'
Function PBMain()
Local lResult As Long
Local Agent As Asciiz * 256
Local TheFtpServer As Asciiz * 256
Local rsvp As Long
Local RemoteFile As Asciiz * 256
Local LocalFile As Asciiz * 256
Local lpszUserName As Asciiz * 16
Local lpszPassword As Asciiz * 12
Agent = "PB/DLL WinInet" ' <== customize HTTP response with this
If Instr(Command$,"?") Then GoTo helpme
'
' Open an Internet session as predefined in the registry
hIOpen = InternetOpen(ByVal VarPtr(Agent), ByVal %INTERNET_OPEN_TYPE_PRECONFIG, ByVal %NULL, ByVal %NULL, ByVal 0)
' If it fails exit
If hIOpen = %NULL Then
StdOut "Could not open an Internet connection"
Exit Function
End If
TheFtpServer = Parse$(Trim$(Command$)," ",1)' <=== your FTP server here
lResult = GetUsernameAndPassword(lpszUserName,lpszPassword)
hIConnect = InternetConnect _
( _
ByVal hIOpen, _
ByVal VarPtr(TheFtpServer), _
ByVal %INTERNET_INVALID_PORT_NUMBER, _
ByVal VarPtr(lpszUserName), _
ByVal VarPtr(lpszPassword), _
ByVal %INTERNET_SERVICE_FTP, _
ByVal 0, _
ByVal 0 _
)
If hIConnect = %NULL Then
InternetCloseHandle(hIOpen)
StdOut "FTP Connect Failed " & Str$(hIConnect)
Exit Function
End If
'
RemoteFile = Parse$(Trim$(Command$)," ",2)' <== the file to GET
LocalFile = Parse$(Trim$(Command$)," ",3) ' <== where you want to PUT it
StdOut "Retrieving " + RemoteFile + " from " + TheFtpServer
rsvp = FtpGetFile _
( _
ByVal hIConnect, _
ByVal VarPtr(RemoteFile), _
ByVal VarPtr(LocalFile), _
ByVal %FALSE, _
ByVal %FILE_ATTRIBUTE_NORMAL, _
ByVal %FTP_TRANSFER_TYPE_UNKNOWN, _
ByVal 0 _
)
If rsvp = %FALSE Then StdOut "File Transfer failed."
'
' Close all the handles
InternetCloseHandle(hIConnect)
InternetCloseHandle(hIOpen)
Exit Function
'
'
HELPME:
StdOut "AppName v1.00"
StdOut "Useage: PBFTP <host/ipaddress> <remotefile> <localfile>
StdOut
StdOut "You will be prompted for username/password"
StdOut "If using anonymous enter ""anonymous"" for username"
StdOut "and your email address for a password"
End Function
'
'
Function GetUsernameAndPassword(lpszUserName As Asciiz,lpszPassword As Asciiz) As Long
StdOut "userName: ";
StdIn Line lpszUserName
lpszPassword = GetPassword
End Function
'
'
Function GetPassword() As String
Local x As Long
Local y As Long
Local i As Long
Local buff As String
StdOut "Password: ";
Do
i = Asc(WaitKey$)
Select Case i
Case 8 'BACKSPACE
x = CursorY
y = CursorX
Locate X,Y - 1
StdOut Chr$(32);
Locate X,Y - 1
If Len(buff) > 0 Then buff = Left$(buff,Len(Buff) - 1)
Case 13,27 '<ENTER><ESC>
StdOut
Exit Do
Case Else
buff = buff + Chr$(i)
StdOut "*";
i = 0
End Select
Function = buff
Loop
End Function
|