473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

File Transfer Need Help

ADE
Hi everyone well from my last post I found what I am looking for

I have some code now that transfers files

I have added a GUI to it and need some help with two things one my
loadtemplate() function if I run it won't open the filetypes I just get the
error message from tkMessageBox but its the right filetype

and the final problem the Variable FILE how can I get it to interact with
GUI once I select an image to send how can I use the selected File to send
using the sendfile function

this is as far as I know the last of my problems

please note that this code has been taken from different parts of the
internet

Cheers
# USAGE: python FileSender.py [file]
from Tkinter import *
import tkFileDialog
import tkMessageBox
import sys, socket

root = Tk()
root.title("My APP")
root.minsize(300, 200)
root.maxsize(500, 400)
def loadtemplate():
filename = tkFileDialog.askopenfilename(filetypes=(("TIFF", ".tiff"),
("JPG", ".jpg"),
("GIF", ".gif")))
if filename:
try:
self.settings["template"].set(filename)
except:
tkMessageBox.showerror("Open Source File", "Failed to read file
\n'%s' " %filename)
return
HOST = 'localhost'
CPORT = 9091
MPORT = 9090
FILE = # I need help here what do I put here
def sendfile():
cs = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
cs.connect((HOST, CPORT))
cs.send("SEND " + FILE)
cs.close()

ms = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ms.connect((HOST, MPORT))

f = open(FILE, "rb")
data = f.read()
f.close()
textbox.insert("Sending File Now...")
ms.send(data)
ms.close()
textbox.insert("File Sent now Closing")

mybrowse = Button(root, text="Browse", command=loadtemplate)
mybrowse.grid(row=0, column=0, sticky=E+W)
mybutton = Button(root, text="Send File", command=sendfile)
mybutton.grid(row=0, column=1, sticky=E+W)
textbox = Text(root)
textbox.grid(row=1, column=0, columnspan=2)
textbox.insert(END, "Depending on size of File this could take a while\n\n")
Jul 18 '05 #1
1 2556
ADE wrote:
Hi everyone well from my last post I found what I am looking for

I have some code now that transfers files

I have added a GUI to it and need some help with two things one my
loadtemplate() function if I run it won't open the filetypes I just get the
error message from tkMessageBox but its the right filetype


The problem is the line: self.settings["template"].set(filename)
This line is out of context. You're not within a class with a "member
variable" called settings. What are you trying to accomplish?

Aren't you looking for somthing like:

....
filename = tkFileDialog.askopenfilename(filetypes=(
("TIFF", ".tiff"), ("JPG", ".jpg"),
("GIF", ".gif")))
try:
sendfile(filename)
except:
tkMessageBox.showerror("Some error sending %" % filename)
....

Of course to do so, you need to change the sendfile() function to a
function that takes 'filename' as argument. As a result, there's no
need for a global variable FILE anymore -- which may solve your 2nd problem:

def sendfile(filename):
...

--
Vincent Wehren

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Limey Drink | last post by:
Hi all, Firstly :-) , is there any where I can search through archived newsgroup posts so I am not cluttering up the newsgroup with repeated queries ? And secondly :-), I know this has...
1
by: Neel Word | last post by:
I need to develop an application (development platform: Win2000; target platform: Win98/ME/NT4/2000/XP), which would require file transfer functionality over dial-up and network. We could...
0
by: GrantS | last post by:
I need urgent help. Done OK for a newbie getting automation of Windows Messenger into a Winform C# app but have three problems that I urgently need pointers to. Point 1 and 2 are the same issue, I...
3
by: SI | last post by:
I need to transfer a file from a central computer(Windows XP) to multiple 'branch' computers(WindowsNT/Windows2000) on a weekly basis. This transfer should be done programmatically in C#, when a user...
11
by: Abhishek | last post by:
I have a problem transfering files using sockets from pocket pc(.net compact c#) to desktop(not using .net just mfc and sockets 2 API). The socket communication is not a issue and I am able to...
6
by: Thomas Connolly | last post by:
I have 2 pages referencing the same codebehind file in my project. Originally the pages referenced separate code behind files. Once I changed the reference to the same file, everything worked...
3
by: Jay | last post by:
Hi, I have some unique situations where i need to transfer a file from Server to client but without any Open or Save dialog box shown to the user. The file should save itself directly to client...
2
by: Jay | last post by:
Hi, I have some unique situations where i need to transfer a file from Server to client but without any Open or Save dialog box shown to the user. The file should save itself directly to client...
1
by: krishan123456 | last post by:
i have tried to send email with attached doc file but when i receive the mail i find the attached file in encoded text instead of actuall attachment.the code that i used to send an email is given...
10
by: David | last post by:
I have googled to no avail on getting specifically what I'm looking for. I have found plenty of full blown apps that implement some type of file transfer but what I'm specifcally looking for is an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.