Exemple #1
0
	def login(self):
		'''
			Check if SSH connection could be established with the remote host, 
			mount the remote file system, and set the current folder of the
			remote file chooser as the location where the remote filesystem is
			mounted.
		'''
		
		self.remotemounter.unmount_remote()
		
		host = self.entry_host.get_text()
		port = self.entry_port.get_text()
		username = self.entry_username.get_text()
		password = self.entry_password.get_text()

		blank_entry = False
		if not host:
			self.update_status('Error: Host is not entered')
			blank_entry = True
		if not username:
			self.update_status('Error: Username is not entered')
			blank_entry = True		

		if blank_entry:
			self.update_status('Login aborted.')
			self.set_login_button_sensitive()
			return

		(port, valid_port) = validate.validate_port(port)
		if not valid_port:
			self.update_status('Error: Invalid port')
			self.update_status('Login aborted.')
			self.set_login_button_sensitive()
			return

		self.update_status('Performing connection checks...')
		(ssh, connection_error) = validate.establish_connection(host, port, username, password)
		if connection_error:
			self.update_status('Error: ' + str(connection_error))
			self.update_status('Login aborted.')
			self.set_login_button_sensitive()
			return
		else:
			ssh.close()

		self.update_status('Logging into remote host...')
		self.remotemounter.login_remote(host, port, username, password)	
		self.update_status('Login successful.')
		self.set_login_button_sensitive()
Exemple #2
0
	def initiate_copy(self):	
		'''
			Check for validity of host, port, username, password, source and
			destination paths and update status and error messages.
			Perform file transfer using the filetransfer module.
			Make the Initiate Copy button sensitive once complete.
		'''

		self.update_status('')
		self.update_status('Performing checks...')
		host = self.entry_host.get_text()
		port = self.entry_port.get_text()
		username = self.entry_username.get_text()
		password = self.entry_password.get_text()

		local_path = self.entry_local_path.get_text()
		remote_path = self.entry_remote_path.get_text()
		source_remote = self.radio_source.get_active()

		blank_entry = False
		if not host:
			self.update_status('Error: Host is not entered')
			blank_entry = True
		if not username:
			self.update_status('Error: Username is not entered')
			blank_entry = True
		if not local_path:
			self.update_status('Error: Local path is not entered')
			blank_entry = True
		if not remote_path:
			self.update_status('Error: Remote path is not entered')
			blank_entry = True

		if blank_entry:
			self.update_status('Transfer aborted.')
			self.set_initiate_copy_button_sensitive()
			return
			
		(port, valid_port) = validate.validate_port(port)
		if not valid_port:
			self.update_status('Error: Invalid port')
			self.update_status('Transfer aborted.')
			self.set_initiate_copy_button_sensitive()
			return

#		Removing '/' at the end of the path to avoid os.path.basename() from
#		returning empty string
		if local_path != '/' and local_path != '~/' and local_path[-1] == '/':
			local_path = local_path[:-1]
		if remote_path != '/' and remote_path != '~/' and remote_path[-1] == '/':
			remote_path = remote_path[:-1]

		self.update_status('Validating local path...')
		(valid_path_local, directory_local) = validate.validate_local(local_path)

		if not valid_path_local:
			self.update_status('Error: Local path does not exist')
			self.update_status('Transfer aborted.')
			self.set_initiate_copy_button_sensitive()
			return

		self.update_status('Establishing connection and validating remote path...')
		(connection_error, valid_path_remote, directory_remote) = validate.validate_remote(remote_path, host, port, username, password)

		if connection_error:
			self.update_status('Error: ' + str(connection_error))
			self.update_status('Transfer aborted.')
			self.set_initiate_copy_button_sensitive()
			return

		if not valid_path_remote:
			self.update_status('Error: Remote path does not exist')
			self.update_status('Transfer aborted.')
			self.set_initiate_copy_button_sensitive()
			return

		if source_remote:
			source_path = remote_path
			destination_path = local_path
			copy_entire_directory = directory_remote
			if not directory_local:
				self.update_status('Error: Destination path is not a directory')
				self.update_status('Transfer aborted.')
				self.set_initiate_copy_button_sensitive()
				return
		else:
			source_path = local_path
			destination_path = remote_path
			copy_entire_directory = directory_local
			if not directory_remote:
				self.update_status('Error: Destination path is not a directory')
				self.update_status('Transfer aborted.')
				self.set_initiate_copy_button_sensitive()
				return

		self.update_status('Copying files...')
		
		output = self.filecopier.initiate_copy(host, port, username, password, source_path, destination_path, source_remote, copy_entire_directory, self.options_dialog.compression, self.options_dialog.preserve, self.options_dialog.limit)
		
		self.update_status('Output:')
		self.update_status(output)
		self.update_status('Transfer Complete.')

		self.set_initiate_copy_button_sensitive()