-
-
Save MikeWills/213ad4fb395c960372fb to your computer and use it in GitHub Desktop.
FTP_ProxyPubnet additional code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
P FTP_ProxyPubnet... | |
P B Export | |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
// FTP_ProxyPubnet(): Log in to an FTP server w/longer fields | |
// | |
// peSocket = Socket created with FTP_open() | |
// peUser = user name of FTP server (or "anonymous") | |
// pePass = Password to use on FTP server (or "user@host") | |
// | |
// Returns 0 if successful, -1 upon error | |
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
D FTP_ProxyPubnet... | |
D PI 10i 0 | |
D peSocket 10i 0 value | |
D peUser * value options(*string) | |
D pePass * value options(*NoPass: *string) | |
D wwRC S 10I 0 | |
D wwMsg S 256 | |
D wwSock S 10I 0 | |
D wwSaveLogLvl S 1 | |
D wwReply S 10I 0 | |
D wwPass S 1000 varying inz('user@host') | |
D wwAcct S 1000 varying | |
D wwDiagMsg S 512 varying | |
/Free | |
initFtpApi() ; | |
if getGlobalAbort() ; | |
return -1 ; | |
endif ; | |
if getSsnLogLvl() >= FTPAPI_LOGLVL_FULL ; | |
wwDiagMsg = '--> FTP_ProxyPubnet(' + %Char(peSocket) | |
+ ': ' + %trimr(%str(peUser)) ; | |
if %Parms >= 3 ; | |
wwDiagMsg += ': xxxxxx' ; | |
if %Parms >= 4 ; | |
wwDiagMsg += ': xxxxxxxx' ; | |
endif ; | |
endif ; | |
diaglog(wwDiagMsg + ')') ; | |
endif ; | |
if sltSsnBySocket(peSocket) < *Zero ; | |
return SetSessionError() ; | |
endif ; | |
// Set password | |
if %Parms >= 3 and %trimr(%str(pePass)) <> '*DEFAULT' ; | |
wwPass = %trimr(%str(pePass)) ; | |
endif ; | |
//************************************************ | |
// Send userid: | |
//************************************************ | |
if sendLine(wwSock: 'USER ' + %trimr(%str(peUser))) < *Zero ; | |
return -1 ; | |
endif ; | |
// 230 User logged in | |
// 331 Password required for user | |
// 332 Account required for user | |
wwReply = Reply(wwSock: wwMsg) ; | |
if wwReply < *Zero ; | |
return -1 ; | |
endif ; | |
if wwReply <> 230 and wwReply <> 331 and wwReply <> 332 ; | |
return setError(FTP_BADUSR: wwMsg) ; | |
endif ; | |
// ************************************************* | |
// * Send password, if required ... | |
// ************************************************* | |
if wwReply = 331 ; | |
// Hide password from logging: | |
wwSaveLogLvl = getSetLogLvl(*Off) ; // Don't write password to log | |
if wwSaveLogLvl >= FTPAPI_LOGLVL_NORMAL ; | |
diagLog('> PASS **********': *On) ; // Log this instead | |
endif ; | |
// ... Send password: | |
wwRC = sendLine(wwSock: 'PASS ' + wwPass) ; | |
setSckLogLvl(wwSock: wwSaveLogLvl) ; // Reset logging level | |
if wwRC < *Zero ; // sendLine was unsuccessful | |
callp close(wwSock) ; | |
return -1 ; | |
endif ; | |
// ... 230 User logged in | |
// ... 202 command not implemented/superfluous | |
// ... 332 Account required for user | |
wwReply = Reply(wwSock: wwMsg) ; | |
if wwReply < *Zero ; | |
return -1 ; | |
endif ; | |
if wwReply <> 230 // User logged in | |
and wwReply <> 202 // Command not implemented | |
and wwReply <> 332 ; // Account required for user | |
return setError(FTP_BADPAS: wwMsg) ; | |
endif ; | |
endif ; | |
//************************************************ | |
// Send account information (believe it or not, | |
// some systems still use this ) | |
//************************************************ | |
if wwReply = 332 ; // Account required for user | |
wwSaveLogLvl = getSetLogLvl(*Off) ; // Don't write account to log | |
if wwSaveLogLvl >= FTPAPI_LOGLVL_NORMAL ; | |
DiagLog('> ACCT **********') ; // Log this instead | |
endif ; | |
wwRC = sendLine(wwSock: 'ACCT ' + wwAcct) ; | |
setSckLogLvl(0: wwSaveLogLvl) ; // Restore account logging | |
if wwRC < *Zero ; // sendLine was unsuccessful | |
return -1 ; | |
endif ; | |
wwReply = Reply(wwSock: wwMsg) ; | |
if wwReply < 0 ; | |
return -1 ; | |
endif ; | |
if wwReply <> 230 // User logged in | |
and wwReply <> 202 ; // Cmd not implmented (OK) | |
return setError(FTP_BADACT: wwMsg) ; // Error | |
endif ; | |
endif ; | |
return *Zero ; | |
/End-free | |
P FTP_ProxyPubnet... | |
P E |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment