|
我可以建立一个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
} |
|