Exemple #1
0
func download(message helper.Message, c net.Conn) {
	file, err := helper.GetFile(message.FileName)
	if err != nil {
		mess := helper.CreateMessage(nil, "Download", "")
		helper.EncodeMessage(*mess, c)
	} else {
		mess := helper.CreateMessage(file, "Download", message.FileName)
		helper.EncodeMessage(*mess, c)
	}
}
Exemple #2
0
//Return a list of all files contained in the server
func list(listFlag bool) {
	if listFlag == true {
		message := helper.CreateMessage(nil, "List", "")
		connection := getConnection("localhost", "8000")
		helper.EncodeMessage(*message, connection)
		mess := helper.DecodeMessage(connection)
		fmt.Println(string(mess.Content))
		connection.Close()
	}
}
Exemple #3
0
func upload(fileName string) {
	if containsFile(fileName) {
		l, err := helper.GetFile(fileName)
		if err != nil {
			fmt.Println(err)
		} else {
			fmt.Println(len(l))
			message := helper.CreateMessage(l, "Upload", fileName)
			connection := getConnection("localhost", "8000")
			encoder := gob.NewEncoder(connection)
			encoder.Encode(message)
			connection.Close()
		}
	}
}
Exemple #4
0
func download(file string) {
	if containsFile(file) {
		message := helper.CreateMessage(nil, "Download", file)
		connection := getConnection("localhost", "8000")
		helper.EncodeMessage(*message, connection)
		mess := helper.DecodeMessage(connection)
		if mess.FileName == "" {
			fmt.Println("NO file found")
		} else {
			file := fmt.Sprintf("./%s/%s", "clientFiles", mess.FileName)
			helper.WriteFile(file, mess.Content)
		}

		connection.Close()
	}
}
Exemple #5
0
func list(c net.Conn) {
	files := getFiles()
	mess := helper.CreateMessage([]byte(files), "List", "")
	helper.EncodeMessage(*mess, c)
}