Tcl/Tk Scripting

Programming, for all ages and all languages.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Tcl/Tk Scripting

Post 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?
Only Human
Neo(out)

Re:Tcl/Tk Scripting

Post 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)
mystran

Re:Tcl/Tk Scripting

Post 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. :)
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Tcl/Tk Scripting

Post 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.
Only Human
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Tcl/Tk Scripting

Post 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?
Only Human
mystran

Re:Tcl/Tk Scripting

Post 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.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Tcl/Tk Scripting

Post 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?
Only Human
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Tcl/Tk Scripting

Post 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>
Only Human
mystran

Re:Tcl/Tk Scripting

Post 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.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Tcl/Tk Scripting

Post 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.
Only Human
mystran

Re:Tcl/Tk Scripting

Post 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).
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Tcl/Tk Scripting

Post by Neo »

Ok i'll try that out and let you know.
Only Human
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Tcl/Tk Scripting

Post by Neo »

Will I face any problems in FTP if i always set the transfer mode to binary even when transferring text files?
Only Human
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Tcl/Tk Scripting

Post 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.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Tcl/Tk Scripting

Post by Neo »

what do you mean by that
Only Human
Post Reply