⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftp_lib.tcl

📁 genesis 2000 v9.1软件下载
💻 TCL
📖 第 1 页 / 共 4 页
字号:
			}					delete_sent {			  switch $rc {			    2       {			               set complete_with 1			            }			    default {				       set errmsg "Error deleting file \"$ftp(File)\"!"				       set complete_with 0				     }			  }			}					rename	{			  PutsCtrlSock "RNFR $ftp(RenameFrom)"  		  	  set ftp(State) rename_to			}					rename_to {			  switch $rc {			    3       {			  	       PutsCtrlSock "RNTO $ftp(RenameTo)"  		  	  	       set ftp(State) rename_sent			            }			    default {				       set errmsg "Error renaming file \"$ftp(RenameFrom)\"!"				       set complete_with 0				     }			  }			}		rename_sent {			  switch $rc {			    2     {			               set complete_with 1			            }			    default {				       set errmsg "Error renaming file \"$ftp(RenameFrom)\"!"				       set complete_with 0				     }			  }			}					put_active 	{			  if {[OpenActiveConn]} {			    	PutsCtrlSock "PORT $ftp(LocalAddr),$ftp(DataPort)"			  	set ftp(State) put_open			  } else {				set errmsg "Error setting port!"			  }			}								put_passive	{			               PutsCtrlSock "PASV"			  	       set ftp(State) put_open			}					put_open {			  switch $rc {			    2  {			         if {$ftp(Mode) == "passive"} {				     if {![OpenPassiveConn $buffer]} {				         set errmsg "Error setting PASSIVE mode!"				       	 set complete_with 0				     }				 }   			         PutsCtrlSock "STOR $ftp(RemoteFilename)"			         set ftp(State) put_sent			       }			    default {			              if {$ftp(Mode) == "passive"} {				          set errmsg "Error setting PASSIVE mode!"				      } else {				          set errmsg "Error setting port!"				      }  				      set complete_with 0				    }			  }		}					put_sent	{			  switch $rc {			    1       {			               set ftp(State) put_close			            }			    default {			              if {$ftp(Mode) == "passive"} {			    	         # close already opened DataConnection			    	         unset state(data)				      }  				       set errmsg "Error opening connection!"				       set complete_with 0				     }			  }		}					put_close	{			  switch $rc {			    2       {			  	       set complete_with 1			            }			    default {				       set errmsg "Error storing file \"$ftp(RemoteFilename)\"!"				       set complete_with 0				     }			  }		}					append_active 	{			  if {[OpenActiveConn]} {			    	PutsCtrlSock "PORT $ftp(LocalAddr),$ftp(DataPort)"			  	set ftp(State) append_open			  } else {				set errmsg "Error setting port!"			  }			}								append_passive	{			               PutsCtrlSock "PASV"			  	       set ftp(State) append_open			}					append_open {			  switch $rc {			    2  {			         if {$ftp(Mode) == "passive"} {				     if {![OpenPassiveConn $buffer]} {				         set errmsg "Error setting PASSIVE mode!"				       	 set complete_with 0				     }				 }   			         PutsCtrlSock "APPE $ftp(RemoteFilename)"			         set ftp(State) append_sent			       }			    default {			              if {$ftp(Mode) == "passive"} {				          set errmsg "Error setting PASSIVE mode!"				      } else {				          set errmsg "Error setting port!"				      }  				      set complete_with 0				    }			  }		}					append_sent	{			  switch $rc {			    1       {			               set ftp(State) append_close			            }			    default {			              if {$ftp(Mode) == "passive"} {			    	         # close already opened DataConnection			    	         unset state(data)				      }  				       set errmsg "Error opening connection!"				       set complete_with 0				     }			  }		}					append_close	{			  switch $rc {			    2       {			  	       set complete_with 1			            }			    default {				       set errmsg "Error storing file \"$ftp(RemoteFilename)\"!"				       set complete_with 0				     }			  }		}					reget_active 	{			  if {[OpenActiveConn]} {			    	PutsCtrlSock "PORT $ftp(LocalAddr),$ftp(DataPort)"			  	set ftp(State) reget_restart			  } else {				set errmsg "Error setting port!"			  }		}					reget_passive	{			               PutsCtrlSock "PASV"			  	       set ftp(State) reget_restart		}					reget_restart {			  switch $rc {			    2 { 			         if {$ftp(Mode) == "passive"} {				     if {![OpenPassiveConn $buffer]} {				         set errmsg "Error setting PASSIVE mode!"				       	 set complete_with 0				     }				 }   			         if {$ftp(FileSize) != 0} {				    PutsCtrlSock "REST $ftp(FileSize)"	               		    set ftp(State) reget_open				 } else {			            PutsCtrlSock "RETR $ftp(RemoteFilename)"			           set ftp(State) reget_sent				 } 			       }			    default {				       set errmsg "Error restarting filetransfer of \"$ftp(RemoteFilename)\"!"				       set complete_with 0				     }			  }			}					reget_open {			  switch $rc {			    2  -			    3  {			         PutsCtrlSock "RETR $ftp(RemoteFilename)"			         set ftp(State) reget_sent			       }			    default {			              if {$ftp(Mode) == "passive"} {				          set errmsg "Error setting PASSIVE mode!"				      } else {				          set errmsg "Error setting port!"				      }  				      set complete_with 0				    }			   }			 }								reget_sent	{			  switch $rc {			    1 {			         set ftp(State) reget_close			       }			    default {			              if {$ftp(Mode) == "passive"} {			    	         # close already opened DataConnection			    	         unset state(data)				      }  				      set errmsg "Error retrieving file \"$ftp(RemoteFilename)\"!"				      set complete_with 0				    }			   }		}					reget_close	{			  switch $rc {			    2       {			  	       set complete_with 1			            }			    default {				       set errmsg "Error retrieving file \"$ftp(RemoteFilename)\"!"				       set complete_with 0				     }			  }		}		get_active 	{			  if {[OpenActiveConn]} {			    	PutsCtrlSock "PORT $ftp(LocalAddr),$ftp(DataPort)"			  	set ftp(State) get_open			  } else {				set errmsg "Error setting port!"			  }			}					get_passive {			        PutsCtrlSock "PASV"			  	set ftp(State) get_open			    }					get_open {			  switch $rc {			    2  -			    3  {			         if {$ftp(Mode) == "passive"} {				     if {![OpenPassiveConn $buffer]} {				         set errmsg "Error setting PASSIVE mode!"				       	 set complete_with 0				     }				 }   			         PutsCtrlSock "RETR $ftp(RemoteFilename)"			         set ftp(State) get_sent			       }			    default {			              if {$ftp(Mode) == "passive"} {				          set errmsg "Error setting PASSIVE mode!"				      } else {				          set errmsg "Error setting port!"				      }  				      set complete_with 0				    }			   }			 }					get_sent	{			  switch $rc {			    1 {			         set ftp(State) get_close			       }			    default {			              if {$ftp(Mode) == "passive"} {			    	         # close already opened DataConnection			    	         unset state(data)				      }  				      set errmsg "Error retrieving file \"$ftp(RemoteFilename)\"!"				      set complete_with 0				    }			   }		}					get_close	{			  switch $rc {			    2       {			  	       set complete_with 1			            }			    default {				       set errmsg "Error retrieving file \"$ftp(RemoteFilename)\"!"				       set complete_with 0				     }			  }		}				}	# finish waiting 	if {[info exists complete_with]} {		WaitComplete $complete_with	}	# display control channel message	if {[info exists buffer]} {		if {$VERBOSE} {			foreach line [split $buffer \n] {				DisplayMsg "C: $line" control			}		}	}		# display error message	if {[info exists errmsg]} {		set ftp(Error) $errmsg		DisplayMsg $errmsg error	}	# enable fileevent on control socket again	#fileevent $ftp(CtrlSock) readable [list ::FTP::StateHandler $ftp(CtrlSock)]}############################################################################### Type --## REPRESENTATION TYPE - Sets the file transfer type to ascii or binary.# (exported)## Arguments:# type - 		specifies the representation type (ascii|binary)# proc Type {{type ""}} {variable ftp 	if ![info exists ftp(State)] {		DisplayMsg "Not connected!" error		return {}	}	# return current type	if { $type == "" } {		return $ftp(Type)	}	# save current type	set old_type $ftp(Type) 		set ftp(Type) $type	set ftp(State) type	StateHandler		# wait for synchronization	set rc [WaitOrTimeout]	if {$rc} {		return $ftp(Type)	} else {		# restore old type		set ftp(Type) $old_type		return {}	} }############################################################################### NList --## NAME LIST - This command causes a directory listing to be sent from# server to user site.# (exported)# # Arguments:# dir - 		The $dir should specify a directory or other system #			specific file group descriptor; a null argument #			implies the current directory. ## Arguments:# dir - 		directory to list # # Returns:# sorted list of files or "-1" if listing failsproc NList {{dir ""}} {variable ftp 	if ![info exists ftp(State)] {		DisplayMsg "Not connected!" error		return {}	}	set ftp(List) {}	if { $dir == "" } {		set ftp(Dir) ""	} else {		set ftp(Dir) " $dir"	}	# save current type and force ascii mode	set old_type $ftp(Type)	if { $ftp(Type) != "ascii" } {		Type ascii	}	set ftp(State) nlist_$ftp(Mode)	StateHandler	# wait for synchronization	set rc [WaitOrTimeout]	# restore old type	if { [Type] != $old_type } {		Type $old_type	}	unset ftp(Dir)	if {$rc} { 		return [lsort $ftp(List)]	} else {		CloseDataConn		return {}	}    }############################################################################### List --## LIST - This command causes a list to be sent from the server# to user site.# (exported)# # Arguments:# dir - 		If the $dir specifies a directory or other group of #			files, the server should transfer a list of files in #			the specified directory. If the $dir specifies a file#			then the server should send current information on the# 			file.  A null argument implies the user's current #			working or default directory.  # # Returns:# list of files or "-1" if listing failsproc List {{dir ""}} {variable ftp 	if ![info exists ftp(State)] {		DisplayMsg "Not connected!" error		return {}	}	set ftp(List) {}	if { $dir == "" } {		set ftp(Dir) ""	} else {		set ftp(Dir) " $dir"	}        set ftp(ExpectedSize) 0    	# save current type and force ascii mode	set old_type $ftp(Type)	if { $ftp(Type) != "ascii" } {		Type ascii	}	set ftp(State) list_$ftp(Mode)	StateHandler	# wait for synchronization	set rc [WaitOrTimeout]	# restore old type	if { [Type] != $old_type } {		Type $old_type	}	unset ftp(Dir)	if {$rc} { 				# clear "total"-line		set l [split $ftp(List) "\n"]		set index [lsearch -regexp $l "^total"]		if { $index != "-1" } { 			set l [lreplace $l $index $index]		}		# clear blank line		set index [lsearch -regexp $l "^$"]		if { $index != "-1" } { 			set l [lreplace $l $index $index]		}				return $l	} else {		CloseDataConn		return {}	}}############################################################################### FileSize --## REMOTE FILE SIZE - This command gets the file size of the# file on the remote machine. # ATTANTION! Doesn't work properly in ascci mode!# (exported)# # Arguments:# filename - 		specifies the remote file name# # Returns:# size -		files size in bytes or {} in error casesproc FileSize {{filename ""}} {variable ftp 	if ![info exists ftp(State)] {		DisplayMsg "Not connected!" error		return {}	}		if { $filename == "" } {		return {}	} 	set ftp(File) $filename	set ftp(FileSize) 0		set ftp(State) size	StateHandler	# wait for synchronization	set rc [WaitOrTimeout]		unset ftp(File)			if {$rc} {		return $ftp(FileSize)	} else {		return {}	}}############################################################################### ModTime --## MODIFICATION TIME - This command gets the last modification time of the# file on the remote machine.# (exported)# 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -