使用python在电脑和手机之间通过wifi简单传输文件
我希望能够在手机和电脑之间传输文件。手机是可以运行 python 2.5.4 的智能手机,计算机运行的是 windows xp(带有 python 2.5.4 和 3.1.1)。
我想在手机上有一个简单的python程序,可以将文件发送到计算机并从计算机获取文件。手机端应该只在调用时运行,计算机端可以是服务器,尽管最好是不使用大量资源的东西。手机端应该能够查出电脑上相关目录中有什么内容。
目前,我通过在计算机上运行 Windows Web 服务器(呃)和带有 socket.set_default_access_point 的脚本(以便程序可以选择我的路由器的 ssid 或其他传输)和 urlretrieve(以获取文件)在电话上。我使用 smtplib 通过电子邮件以其他方式发送文件。
无论是总体想法、现有计划还是介于两者之间的任何建议,我们将不胜感激。
I'd like to be able to transfer files between my mobile phone and computer. The phone is a smartphone that can run python 2.5.4 and the computer is running windows xp (with python 2.5.4 and 3.1.1).
I'd like to have a simple python program on the phone that can send files to the computer and get files from the computer. The phone end should only run when invoked, the computer end can be a server, although preferably something that does not use a lot of resources. The phone end should be able to figure out what's in the relevant directory on the computer.
At the moment I'm getting files from computer to phone by running windows web server on the computer (ugh) and a script with socket.set_ default _ access_point (so the program can pick my router's ssid or other transport) and urlretrieve (to get the files) on the phone. I'm sending files the other way by email using smtplib.
Suggestions would be appreciated, whether a general idea, existing programs or anything in between.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会使用 paramiko。它安全快速且非常简单。这个怎么样?
因此,我们首先导入模块并指定日志文件:
我们打开 SSH 传输:
接下来我们要进行身份验证。我们可以使用密码来完成此操作:
另一种方法是使用 SSH 密钥:
现在我们可以启动 SFTP 客户端:
现在让我们将文件从远程拉到本地系统:
现在让我们换一种方式:
最后,我们需要关闭 SFTP 连接和传输:
怎么样?对于这个例子,我必须给予信用。
I would use paramiko. It's secure fast and really simple. How bout this?
So we start by importing the module, and specifying the log file:
We open an SSH transport:
Next we want to authenticate. We can do this with a password:
Another way is to use an SSH key:
Now we can start the SFTP client:
Now lets pull a file across from the remote to the local system:
Now lets go the other way:
Lastly, we need to close the SFTP connection and the transport:
How's that?? I have to give credit to this for the example.
我最终在手机上使用 python 的 ftplib,在计算机上使用 FileZilla(一个 ftp 服务器)。优点是高度简单,但可能存在安全问题。
如果有人关心的话,这里是发送和接收文件的客户端代码的核心。实际的实施需要更多的基础设施。
I ended up using python's ftplib on the phone and FileZilla, an ftp sever, on the computer. Advantages are high degree of simplicity, although there may be security issues.
In case anyone cares, here's the guts of the client side code to send and receive files. Actual implementation has a bit more infrastructure.
有一些示例,但是您必须记住,IIRC、PyBluez 只能在 Linux 上运行。
您还有 lightblue,这是一个跨操作系统的蓝牙库。
还有一个完整的脚本,PUTools: Python Utility Tools for PyS60 Python(示例有 Windows 屏幕截图),其中有:
There are a couple of examples out there, but you have to keep in mind that, IIRC, PyBluez will work only on Linux.
You also have lightblue, that is a cross-os bluetooth library.
There is also a complete script, PUTools: Python Utility Tools for PyS60 Python (examples has Windows screenshots), that has a: