Greenseed Posted April 29, 2005 Posted April 29, 2005 Hi! thx to everyone for the respond to my post you have been a great help. i start a process with a ftp server on a computer i have a little script that check for the proccess running when the process goes off my little script send a ftp -s:command/txt to the ftp server to restart the process missing. i wan to be more optimized i see some people working with dll to access ftp! to have a function to connect on a ftp and a function to send raw command all with dllcall and it return the answer of the server? im working on me too, but lol im a little noodle in the soup with many guys better then me there Greenseed GreenseedMCSE+I, CCNA, A+Canada, QuebecMake Love Around You.
Greenseed Posted May 1, 2005 Author Posted May 1, 2005 j'ai pris le script poster par SumTingWong et j'ai cree la fonction connect, sendcommand et closeconnection, mais j'en suis sure elle peu etre meilleure. expandcollapse popup;~ MsgBox(4096,'debug line ~23' , '$nRetCode:' & @lf & $nRetCode);### Debug MSGBOX ;~ Usage _ftpconnect("Host","User","Password", Type) ;~ Type = $FTP_TRANSFER_TYPE_ASCII or $FTP_TRANSFER_TYPE_BINARY ;~ return the connection number ;~ Usage _ftpcommand("connectionnumber","command") ;~ return ??? ;~ Usage _closeconnection("connectionnumber") ;~ return ??? ; Access types for InternetOpen() Global $INTERNET_OPEN_TYPE_PRECONFIG = 0 Global $INTERNET_OPEN_TYPE_DIRECT = 1 Global $INTERNET_OPEN_TYPE_PROXY = 3 Global $INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4 ; Service types for InternetConnect() Global $INTERNET_SERVICE_FTP = 1 Global $INTERNET_SERVICE_GOPHER = 2 Global $INTERNET_SERVICE_HTTP = 3 Global $INTERNET_DEFAULT_FTP_PORT = 21 Global $INTERNET_FLAG_ASYNC = 0x10000000 Global $INTERNET_FLAG_PASSIVE = 0x08000000 Global $FTP_TRANSFER_TYPE_UNKNOWN = 0x00000000 Global $FTP_TRANSFER_TYPE_ASCII = 0x00000001 Global $FTP_TRANSFER_TYPE_BINARY = 0x00000002 Dim $hWininet Dim $nRetCode Dim $hInternet ;~ exemple ;~ global $INTERNET_DEFAULT_FTP_PORT = 21210 ;~ $cNumber = _openconnection("127.0.0.1","anonymous","allo@bouda.com",$FTP_TRANSFER_TYPE_ASCII) ;~ sleep(5000) ;~ _sendcommand($cNumber,"salut gros pachat") ;~ _closeconnection($cNumber) Func _openconnection($sServer, $sUserName, $sPassword,$nType = 0, $nPassive = 1) $hWininet = DllOpen("wininet.dll") If $hWininet = -1 Then Return endif Local $aDllRet Local $nRet = 0 Local $hConnect $aDllRet = DllCall($hWininet, "ptr", "InternetOpen", _ "str", "AutoITFTPUDF", _ "long", $INTERNET_OPEN_TYPE_DIRECT, _ "int", 0, _ "int", 0, _ "long", $INTERNET_FLAG_ASYNC) If Not @error And $aDllRet[0] <> 0 Then $hInternet = $aDllRet[0] If $nPassive Then $nPassive = $INTERNET_FLAG_PASSIVE Else $nPassive = 0 EndIf $aDllRet = DllCall($hWininet, "ptr", "InternetConnect", _ "ptr", $hInternet, _ "str", $sServer, _ "long", $INTERNET_DEFAULT_FTP_PORT, _ "str", $sUserName, _ "str", $sPassword, _ "long", $INTERNET_SERVICE_FTP, _ "long", $nPassive, _ "int", 0) If Not @error And $aDllRet[0] <> 0 Then $hConnect = $aDllRet[0] else $hConnect = 0 endif endif Return $hConnect EndFunc func _sendcommand($hConnect,$Command) Local $hInternet Local $aDllRet Local $nRet = 0 $aDllRet = DllCall($hWininet, "int", "FtpCommand", _ "ptr", $hConnect, _ "int", 0, _ "long", $FTP_TRANSFER_TYPE_ASCII, _ "str", $Command, _ "int", 0, _ "int", 0) If Not @error Or $aDllRet[0] <> 0 Then $nRet = -1 Else $aDllRet = DllCall("kernel32.dll", "long", "GetLastError") If Not @error Then $nRet = $aDllRet[0] EndIf return $nret endfunc func _closeconnection($hConnect) Local $hConnect DllCall($hWininet, "int", "InternetCloseHandle", "ptr", $hConnect) DllCall($hWininet, "int", "InternetCloseHandle", "ptr", $hInternet) DllClose($hWininet) endfunc GreenseedMCSE+I, CCNA, A+Canada, QuebecMake Love Around You.
FreeRider Posted April 14, 2008 Posted April 14, 2008 Salut Greenseed Un cousin de la vieille Europe à besoin d'aide et ta fonction SendCommand me serait utile. Est-ce qu'elle fonctionne avec les commandes Ftp du genre "Append" ? Parce que je tente de le faire depuis un bon moment et je n'y arrive pas. D'avance merci de ton aide. FreeRider FreeRiderHonour & Fidelity
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now