Page 1 of 2
Tcl/Tk Scripting
Posted: Wed Jan 19, 2005 7:27 am
by Neo
Is there any way we can use the 'test' function in Tk programs?
i want to write a function that tests if a file is a file/directory.
Any good ref docs?
Re:Tcl/Tk Scripting
Posted: Fri Jan 21, 2005 9:20 am
by Neo(out)
Ok got that one covered.
Another doubt though. How do we check to se if a string variable has valid data in it. (no spaces or empty)
Re:Tcl/Tk Scripting
Posted: Fri Jan 21, 2005 3:56 pm
by mystran
Check if it's empty (or just spaces). Then if it isn't, it contains something else. For anything more specific you'll have to say what "valid data" means.
Re:Tcl/Tk Scripting
Posted: Fri Jan 21, 2005 8:52 pm
by Neo
is there any function to check if its empty/spaces? cause right now i use this
Code: Select all
if {![string length [string trim $var]]} {
puts stdout "zero length";
}
and it works fine. I just wanted to know if there was a simpler way.
Re:Tcl/Tk Scripting
Posted: Fri Jan 21, 2005 8:56 pm
by Neo
BTW I have another little problem now.
I want to create a procedure to display error messages which are stored in a err Array (global).
My procedures may call this error procedure with an index name/number and i want the appropriate error message to be printed out. I cannot seem to be able to display the error strings using upvar, I do not know why.
Does any one have some example code of this?
Re:Tcl/Tk Scripting
Posted: Fri Jan 21, 2005 10:50 pm
by mystran
Your code doesn't look that complicated to me. Besides, when you make it a function, it's just a function call everywhere else.
The array question I cannot answer; it's simply been too long since I wrote any TCL. But posting your non-working code here might help others spot the problem.
Re:Tcl/Tk Scripting
Posted: Sat Jan 22, 2005 5:16 am
by Neo
I just declared the array global insiide the proc and am using that right now.
Anyway now I'm trying to create sockets and connecting to remote machines form them. Will post here if I need more help.
BTW anyone here who has used sockets from scripts?
Re:Tcl/Tk Scripting
Posted: Sun Jan 23, 2005 3:48 am
by Neo
I've come across a point in the RFC's for FTP (959) that I cant seem to understand properly.
FTP reuqires 2 connections one control and another data connection.
How do i set up a data port connection? is there some predefined port for this, 21 is the control port only AFAIK.
<edit>
Should have read this ....
The RFC says that
Both the user and the server-DTPs have a default data port. The user-process default data port is the same as the control connection port (i.e., U). The server-process default data port is the port adjacent to the control connection port (i.e., L-1).
Does this mean 22 is the server data port?
</edit>
Re:Tcl/Tk Scripting
Posted: Sun Jan 23, 2005 5:06 am
by mystran
Port 20 is used for FTP data, although you generally either tell the server your port with a PORT command, or use passive mode, in which case server gives you an address to connect to.
Not that I've ever bothered to really learn FTP. So far HTTP (or some 3rd party library capable of FTP) has sufficed for my purposes.
Port 22 btw is SSH.
Re:Tcl/Tk Scripting
Posted: Sun Jan 23, 2005 6:50 am
by Neo
I've been trying to manually replay a file transfer session using FTP, so far all I've been able to do is use execute only the Access Control commands (USER, PASS, PWD etc).
I tried a RETR but just get an errror saying
425 Can't build data connection: Connection timed out.
I can't transfer anything either way.
How is this done? I can't open a connection to port 20 too.
Is someone knows the steps that take place before and after a file transfer please let me know.
Re:Tcl/Tk Scripting
Posted: Sun Jan 23, 2005 9:16 am
by mystran
Like I said, you have two options:
1. Listen to some port, and tell the port to the server using PORT command. Server will then connect to that port to open the data connection. To do this manually you need netpipes or equivalent as plain telnet can't listen.
2. Switch to passive mode (PASV or something) in which case the server will give you the hostname and port (in rather esoteric notation) to use. You can then connect to that port (don't remember if you need/can do it before the transfer command, the RFC will tell though).
Re:Tcl/Tk Scripting
Posted: Sun Jan 23, 2005 9:21 pm
by Neo
Ok i'll try that out and let you know.
Re:Tcl/Tk Scripting
Posted: Sun Jan 23, 2005 10:19 pm
by Neo
Will I face any problems in FTP if i always set the transfer mode to binary even when transferring text files?
Re:Tcl/Tk Scripting
Posted: Mon Jan 24, 2005 12:28 am
by Candy
Neo wrote:
Will I face any problems in FTP if i always set the transfer mode to binary even when transferring text files?
No.
The files will however have the line endings with which you sent them.
Re:Tcl/Tk Scripting
Posted: Mon Jan 24, 2005 4:23 am
by Neo
what do you mean by that