51Testing软件测试论坛
标题:
如何用TCL实现一个FTP客户端?
[打印本页]
作者:
kevinbj
时间:
2006-10-26 18:13
标题:
如何用TCL实现一个FTP客户端?
我可以建立一个21端口的连接,但20端口就不会搞了。请高手帮助!先谢过了!
#################Creat Socket proc
proc Socket_client { host port timeout} {
global connected
after $timeout {set connected timeout}
set sock [socket -async $host $port]
fileevent $sock w {set connected ok}
vwait connected
if { $connected == "timeout" } {
return -code error timeout
} else {
return $sock
}
}
###############Login
proc Login {Lsock21 Username Pass} {
puts $Lsock21 "USER $Username"
puts [gets $Lsock21]
puts $Lsock21 "PASS $Pass"
set loginSucc [gets $Lsock21]
if {$loginSucc == {230 User logged in}} {
return 1
} else {
return 0
}
}
#############server accept
proc Accept {newSock addr port} {
puts "Accepted $newSock from $addr port $port"
}
proc Socket20_Client {listenport} {
set listensocket [socket -server Accept $listenport]
vwait listensocket
ruten $listensocket
}
#############Main Proc
#############FTP port 21 connection
set sock21 [Socket_client {10.21.4.106} {21} {30000}]
fconfigure $sock21 -buffering line
puts [gets $sock21]
set Login21 [Login "$sock21" {anonymous} {
a@b.com
}]
set socketMsg [fconfigure $sock21 -sockname]
set localport [lindex $socketMsg 2]
set portHi [ expr round( ($localport + 2) / 256)]
set portLo [ expr round( fmod($localport, 256))]
puts $sock21 "port 10, 21, 4, 16, $portHi, $portLo"
puts $sock21 {NLST}
#set socket20 [Socket20_Client [expr $localport + 2]]
puts $sock21 {}
after 1000 {
#puts [gets $socket]
#set sock2102 [read -nonewline $sock21]
#puts $sock2102
#set sock1 [socket -async 10.21.4.106 20]
#puts [fconfigure $sock1]
#close $sock21
#close $sock1
}
作者:
Valve
时间:
2008-10-14 17:04
你是用Socket来做???好很不简单啊。。
你可以用Expert来做。。那个比较简单。。
作者:
xgl425
时间:
2011-8-15 18:44
请教:
c写个unix socket ,如何用tcl加载 C语言写的扩展包?
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2