客户端代码:
#-*-encoding:utf-8-*-
import socket import os import sys import math import time import threading
def getFileSize(file): file.seek(0, os.SEEK_END) fileLength = file.tell() file.seek(0, 0) return fileLength
def getFileName(fileFullPath): index = fileFullPath.rindex('\\') if index == -1: return fileFullPath else: return fileFullPath[index+1:]
def transferFile(): fileFullPath = r"%s" % raw_input("File path: ").strip("\"") if os.path.exists(fileFullPath): timeStart = time.clock() file = open(fileFullPath, 'rb') fileSize = getFileSize(file) client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect((targetHost, targetPort)) # send file size client.send(str(fileSize)) response = client.recv(1024) # send file name client.send(getFileName(fileFullPath)) response = client.recv(1024) # send thread count client.send(str(threadCount)) response = client.recv(1024)
|