Python for ipaq
Martin Franklin
martin.franklin at westgeo.com
Tue Oct 23 07:49:10 EDT 2001
Karol Makowski wrote:
> On 23 Oct 2001 10:50:46 GMT, Karol Makowski wrote:
>> On Tue, 23 Oct 2001 06:47:52 -0400, Steve Holden wrote:
>>> Sample FTP code in ftpStream.py at
>> thanks, i'll check it.
>
> it's not suitable for my needs, sorry.
> I need an ftp client which will dynamicaly get filename/folder
> from a commandline.
> On that crappy ipaq there is no any smb/nfs protocol and i've got some
> app which need to send and recive some files to work correctly, so i
> thought i'll get some simple ftp client in python, cause python it's
> avaiable for ipaq. ftp client should be run from command line like this:
> ftp.py -g somefile (download file from server)
> ftp.py -s somefile (send some file to server)
>
> It's all i need, server, username/pass is defined in program,
> while filename and/or path should be a variable.
>
> Thanks for help.
>
You could role your own like this:-
#!/usr/local/bin/python
# ftp.py ....
import ftplib, sys
if sys.argv[1]=='-g':
# get it is!
action='GET'
elif sys.argv[1]=='-s':
# send (aka PUT)
action='PUT'
else:
print """USAGE:
to get a file from server:-
ftp.py -g remote_file_name local_file_name
to put a file on server:-
ftp.py -s remote_file_name local_file_name
"""
sys.exit()
filename=sys.argv[2]
localfile=sys.argv[3]
ftp=ftplib.FTP('Some.Server.Somewhere')
ftp.login('USERNAME', 'PASSWORD')
ftp.set_debuglevel(0)
if action=='GET':
lfile=open(localfile, 'wb')
def store_local(data):
lfile.write(data)
ftp.retrbinary('RETR %s' %filename, store_local, 32768)
else:
ftp.storbinary('STOR %s' %filename, open(localfile, 'rb'), 32768)
More information about the Python-list
mailing list