473,624 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using ftplib

I'm experimenting with this now and I'm a little confused about
transferring commands. This might be more of an FTP question than
strictly Python, but it's still related to how to use the ftplib methods.

Anyway, if what I want to do is send a command to change the file
permission settings of a file (or files), I assume I would use
transfercmd() and the command would be something like SITE CHMOD 755
name.py, for example.

What I'm confused about is why the documentation says to send a PORT or
PASV command as well. Is this just something that must be done before
each command?

Also, in order to figure out what the FTP commands are to begin with, I
did a little testing in FileZilla and I noted what was being displayed
at the top (things like PORT xxx, STOR xxx, SITE CHMOD, etc. depending
on what I was doing). So I assume these are the 'cmd' parameter. So here
are a couple of questions:

1. Are PORT/PASV necessary to start a transfer?

2. Is the cmd parameter some kind of list, or is it just a string and
you have to call a separate transfercmd() for each command?

3. My burning question: also during every transfer I made in FileZilla,
I see that it sometimes sends a TYPE A or TYPE I command as well. What
are these, and are they also necessary when I'm using transfercmd()?

Thanks!
John
May 1 '06 #1
5 5615
John Salerno wrote:
I'm experimenting with this now and I'm a little confused about
transferring commands. This might be more of an FTP question than
strictly Python, but it's still related to how to use the ftplib
methods.

Anyway, if what I want to do is send a command to change the file
permission settings of a file (or files), I assume I would use
transfercmd() and the command would be something like SITE CHMOD 755
name.py, for example.

What I'm confused about is why the documentation says to send a PORT
or PASV command as well. Is this just something that must be done
before each command?

Also, in order to figure out what the FTP commands are to begin with,
I did a little testing in FileZilla and I noted what was being
displayed at the top (things like PORT xxx, STOR xxx, SITE CHMOD,
etc. depending on what I was doing). So I assume these are the 'cmd'
parameter. So here are a couple of questions:

1. Are PORT/PASV necessary to start a transfer?
Indeed. FTP is a tricky (and _very_ old) protocol that does things in a
very different manner to the later (simpler) protocols like HTTP. Not
sure how familiar you are with FTP, so my apologies if I wind up
repeating stuff you know already:

FTP sessions typically have *two* connections: the "control"
connection, and the "data" connection. The control connection is from
the client to the server (typically port 21 on the server side), and is
used to send commands to the server and obtain responses.

The PORT command tells the server to open a data connection to the
client (yes, that's not a typo: from the server to the client) and the
parameters tell the server the address and port to connect to. This is
the "active" (or default) mode for FTP (although due to the heavy use
of NAT these days, "passive" mode is probably as, or more common in
practice).

The PASV command is the reverse of the PORT command: it requests the
server listen on a new port for a data connection from the client to
the server.

Data is never transferred over the control connection, it always goes
over the separate data connection, hence why PORT or PASV are required
before initiating a transfer.

See RFC 959 for the full spec (gawd, it's been a long time since I read
that ... amazed I still remember the number):
http://www.faqs.org/rfcs/rfc959.html

2. Is the cmd parameter some kind of list, or is it just a string and
you have to call a separate transfercmd() for each command?
Sorry, I haven't used ftplib yet, but a brief glance at the code
suggests to me that it's just a string and you probably do need to call
a separate transfercmd for each command.
3. My burning question: also during every transfer I made in
FileZilla, I see that it sometimes sends a TYPE A or TYPE I command
as well. What are these, and are they also necessary when I'm using
transfercmd()?


TYPE I indicates that an "Image" transfer is to take place (though this
is more commonly referred to nowadays as a "binary" transfer). In an
binary transfer the data is transferred verbatim with no
transformations .

TYPE A indicates that an ASCII transfer is to take place. An ASCII
transfer is intended for use with text files and indicates that the
data should be transformed from the native text format on the client
platform to the native text format on the server platform. For example,
transferring a file from a DOS/Windows client to a UNIX/Linux platform
in ASCII mode would convert CRLF line endings (ASCII char 13 + ASCII
char 10) to LF line endings (ASCII char 10).

There are other transfer modes as well, though I forget exactly what
they are (there's probably one for EBCDIC <shudder> :-).

Take a look at the storbinary, storlines, retrbinary and retrlines
methods of the FTP object: looks like they perform the appropriate TYPE
command for you, then pass the specified command to transfercmd.
HTH,

Dave.
--

May 1 '06 #2
Dave Hughes wrote:
Indeed. FTP is a tricky (and _very_ old) protocol that does things in a
very different manner to the later (simpler) protocols like HTTP. Not
sure how familiar you are with FTP, so my apologies if I wind up
repeating stuff you know already:
Thanks very much, all that information was great to have.
TYPE A indicates that an ASCII transfer is to take place. An ASCII
transfer is intended for use with text files and indicates that the
data should be transformed from the native text format on the client
platform to the native text format on the server platform. For example,
transferring a file from a DOS/Windows client to a UNIX/Linux platform
in ASCII mode would convert CRLF line endings (ASCII char 13 + ASCII
char 10) to LF line endings (ASCII char 10).

There are other transfer modes as well, though I forget exactly what
they are (there's probably one for EBCDIC <shudder> :-).

Take a look at the storbinary, storlines, retrbinary and retrlines
methods of the FTP object: looks like they perform the appropriate TYPE
command for you, then pass the specified command to transfercmd.


So if I already have files on the server and I want to change file
permissions, do I need to mess with TYPE A/TYPE I commands, or are those
strictly for when you *transfer* files? Because I just did a quick test
of changing file permissions through my FTP program, and it still sent a
TYPE A command in the process. I know that the retr and stor methods
might do this automatically, but if I don't need to use those, and just
need to use transfercmd (assuming this *is* the right method to use when
changing file permissions), do I need to manually send a TYPE A/I
command as well?
May 1 '06 #3
John Salerno wrote:
[...]

So if I already have files on the server and I want to change file
permissions, do I need to mess with TYPE A/TYPE I commands, or are those
strictly for when you *transfer* files? Because I just did a quick test
of changing file permissions through my FTP program, and it still sent a
TYPE A command in the process. I know that the retr and stor methods
might do this automatically, but if I don't need to use those, and just
need to use transfercmd (assuming this *is* the right method to use when
changing file permissions), do I need to manually send a TYPE A/I
command as well?


The answer is "probably not", but a better answer is "try it in the
interactive interpreter and see".

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

May 2 '06 #4
Steve Holden wrote:
John Salerno wrote:
[...]

So if I already have files on the server and I want to change file
permissions, do I need to mess with TYPE A/TYPE I commands, or are
those strictly for when you transfer files? Because I just did a
quick test of changing file permissions through my FTP program,
and it still sent a TYPE A command in the process. I know that the
retr and stor methods might do this automatically, but if I don't
need to use those, and just need to use transfercmd (assuming this
is the right method to use when changing file permissions), do I
need to manually send a TYPE A/I command as well?


The answer is "probably not", but a better answer is "try it in the
interactive interpreter and see".


As far as I recall your speculation is indeed correct: a TYPE command
is only necessary before a transfer (it's only used to transform data
passing over the secondary data connection). I'm reasonably certain you
don't need *anything* before a SITE command (like SITE CHMOD), not even
PORT or PASV (unless the specific SITE command being invoked requires a
data transfer, which CHMOD shouldn't). But as Steve suggests, the best
way to know for sure is to give it a whirl and see what happens :-)

Incidentally, you might like to experiment with the command line ftp
client. On both Linux and Windows, the "quote" command can be used to
send commands "raw" to the FTP server. For example:

ftp> quote SITE CHMOD 755 afile.py
Dave.

--

May 2 '06 #5
Dave Hughes wrote:
As far as I recall your speculation is indeed correct: a TYPE command
is only necessary before a transfer (it's only used to transform data
passing over the secondary data connection). I'm reasonably certain you
don't need *anything* before a SITE command (like SITE CHMOD), not even
PORT or PASV (unless the specific SITE command being invoked requires a
data transfer, which CHMOD shouldn't). But as Steve suggests, the best
way to know for sure is to give it a whirl and see what happens :-)


Thanks. I sometimes forget I can experiment with the interactive
interpreter, but I also didn't want to screw up anything on my server
space by doing something weird! :)
May 2 '06 #6

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

Similar topics

3
19832
by: python | last post by:
Hi: I want to write a procedure to automatically upload some files for me, but I'm getting stuck. Before I write my own gruesome put() function, I wanted to check if there is an easier way. Here's what I can do so far: >>>import ftplib >>>conn = ftplib.FTP('ftp.example.com') >>>conn.login(user='userid', passwd='passwd')
5
7829
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of files via FTP. I'm using ftplib to do it, and for each file I'm using transfercmd("STOR " + myfile) to get the socket, then uploading 4096 bytes at a time and providing status updates via a GUI interface. Finally, I close the socket, set it to...
0
2117
by: Joshua Burvill | last post by:
Hello, I am trying to print something to a print server using the following function but I get errors, does anyone have any pointers? Rgds, Josh Traceback (most recent call last): File "<pyshell#2>", line 1, in ?
1
2990
by: Ëåîíîâ Àëåêñåé | last post by:
Hello! I use this code: from ftplib import FTP def handleDownload(block): file.write(block) print "." file = open('1', 'wb') ftp = FTP('ftp.utk.ru')
4
2255
by: John Salerno | last post by:
I've tried this already and it seems to work, but I'm curious if it's okay to use urllib when trying to access a url that begins with ftp:// instead of http://. Does this matter? It's only a text file, so it's not really an FTP server I'm accessing, I don't think. I wasn't sure if using ftplib would be overkill in this case, or if you even could use it at all if you just want to get the page itself (the txt file). Thanks.
12
6178
by: johnny | last post by:
I have taken a look at the code that dose one download at time, in multi threaded manner: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/465531 What I wanted to do is, make it download multiple files at the same time. I am new to python and have gone over "Dive In To Python" yesterday. Can some give a idea what I need to do. Once I understand the big picture, then I can piece together.
1
3176
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket). The README file in the Tools/freeze directory of the Python-2.4.4 distribution says the following (and many other things): Previous versions of Freeze used a pretty simple-minded algorithm to
1
3294
by: Merrigan | last post by:
Hi All, I have written a little script to upload some files to an ftp folder. The problem is as follows : I wrote the script on my windows laptop, and I want to run it from mylinux server. Everything worked fine so I uploaded it to my linux machine. Every time I tun the script I get the following error: ***************************************************************************************************************************
1
6074
by: loial | last post by:
Trying to use ftplib.FTP.nlst() method to list the files in a directory on a FTP server. It works fine except when there are no files in the directory. Then it gives the error ftplib.error_perm: 550 No files found. How can I handle this cleanly?
0
8234
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8620
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8474
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.