473,740 Members | 9,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ftplib - uploading files using transfercmd?

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("ST OR " +
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 None, then move on to the next file. I'm using
active FTP to upload.

The first file uploads just fine, but on the second file I'm
consistently seeing a weird problem where the response to the PORT
command (sent by self.makeport() ) comes *after* the STOR command is
sent. The order in which the commands are sent doesn't seem to differ,
only the order in which the FTP server responds differs. This causes
the transfercmd() call to see an 'error' because the repsonse to the
PORT command is a 200, but it expects a response in the 100s. I've
posted the actual FTP debug calls below.

I can resolve the problem by continually re-logging into the server,
but I'd like to avoid doing that if possible. I've tried setting the
file mode to binary as well as ASCII with the same results.

Any clues on what I may be going wrong? Has anyone seen anything like
this before? I couldn't find anything while googling... TIA for any
help!

Kevin

#uploading first file...
*cmd* u'CWD /newlook/tutorial/'
*put* u'CWD /newlook/tutorial/\r\n'
*get* '250 CWD command successful.\r\n '
*resp* '250 CWD command successful.'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Type set to I.\r\n'
*resp* '200 Type set to I.'
item = /newlook/tutorial/pub/working_with_th emes.htm
*cmd* 'PORT 192,168,1,103,1 3,230'
*put* 'PORT 192,168,1,103,1 3,230\r\n'
*get* '200 PORT command successful.\r\n '
*resp* '200 PORT command successful.'
*cmd* u'STOR /newlook/tutorial/pub/working_with_th emes.htm'
*put* u'STOR /newlook/tutorial/pub/working_with_th emes.htm\r\n'
*get* '150 Opening BINARY mode data connection for
/newlook/tutorial/pub/working_with_th emes.htm.\r\n'
*resp* '150 Opening BINARY mode data connection for
/newlook/tutorial/pub/working_with_th emes.htm.'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '226 Transfer complete.\r\n'
*resp* '226 Transfer complete.'

#uploading second file...
item = /newlook/tutorial/pub/Changing_Page_P roperties_1.htm
*cmd* 'PORT 192,168,1,103,1 3,231'
*put* 'PORT 192,168,1,103,1 3,231\r\n'
*get* '200 Type set to I.\r\n'
*resp* '200 Type set to I.'
*cmd* u'STOR /newlook/tutorial/pub/Changing_Page_P roperties_1.htm '
*put* u'STOR /newlook/tutorial/pub/Changing_Page_P roperties_1.htm \r\n'
*get* '200 PORT command successful.\r\n '
*resp* '200 PORT command successful.'
Traceback (most recent call last):
File "F:\oss\eclass\ eclass_builder\ editor.py", line 1083, in
UploadPage
self.UploadFile s(ftpfiles)
File "F:\oss\eclass\ eclass_builder\ editor.py", line 921, in
UploadFiles
ftp.UploadFiles ()
File "F:\oss\eclass\ eclass_builder\ editor.py", line 1908, in
UploadFiles
self.mysocket = self.host.trans fercmd('STOR ' + dir + myitem)
File "C:\PYTHON23\li b\ftplib.py", line 345, in transfercmd
return self.ntransferc md(cmd, rest)[0]
File "C:\PYTHON23\li b\ftplib.py", line 336, in ntransfercmd
raise error_reply, resp
ftplib.error_re ply: 200 PORT command successful.
Jul 18 '05 #1
5 7836
Kevin Ollivier <ke****@tulane. edu> writes:
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("ST OR " +
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 None, then move on to the next file. I'm using
active FTP to upload. The first file uploads just fine, but on the second file I'm
consistently seeing a weird problem where the response to the PORT
command (sent by self.makeport() ) comes *after* the STOR command is
sent. The order in which the commands are sent doesn't seem to differ,
only the order in which the FTP server responds differs. This causes
the transfercmd() call to see an 'error' because the repsonse to the
PORT command is a 200, but it expects a response in the 100s. I've
posted the actual FTP debug calls below. I can resolve the problem by continually re-logging into the server,
but I'd like to avoid doing that if possible. I've tried setting the
file mode to binary as well as ASCII with the same results. Any clues on what I may be going wrong? Has anyone seen anything like
this before? I couldn't find anything while googling... TIA for any
help! Kevin #uploading first file...
*cmd* u'CWD /newlook/tutorial/'
*put* u'CWD /newlook/tutorial/\r\n'
*get* '250 CWD command successful.\r\n '
*resp* '250 CWD command successful.'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Type set to I.\r\n'
*resp* '200 Type set to I.'
item = /newlook/tutorial/pub/working_with_th emes.htm
*cmd* 'PORT 192,168,1,103,1 3,230'
*put* 'PORT 192,168,1,103,1 3,230\r\n'
*get* '200 PORT command successful.\r\n '
*resp* '200 PORT command successful.'
*cmd* u'STOR /newlook/tutorial/pub/working_with_th emes.htm'
*put* u'STOR /newlook/tutorial/pub/working_with_th emes.htm\r\n'
*get* '150 Opening BINARY mode data connection for
/newlook/tutorial/pub/working_with_th emes.htm.\r\n'
*resp* '150 Opening BINARY mode data connection for
/newlook/tutorial/pub/working_with_th emes.htm.' * >*cmd* 'TYPE I'
* >*put* 'TYPE I\r\n'
* >*get* '226 Transfer complete.\r\n'
* >*resp* '226 Transfer complete.'
#uploading second file...
item = /newlook/tutorial/pub/Changing_Page_P roperties_1.htm
*cmd* 'PORT 192,168,1,103,1 3,231'
*put* 'PORT 192,168,1,103,1 3,231\r\n'
*get* '200 Type set to I.\r\n'
*resp* '200 Type set to I.'
*cmd* u'STOR /newlook/tutorial/pub/Changing_Page_P roperties_1.htm '
*put* u'STOR /newlook/tutorial/pub/Changing_Page_P roperties_1.htm \r\n'
*get* '200 PORT command successful.\r\n '
*resp* '200 PORT command successful.'
Traceback (most recent call last):
File "F:\oss\eclass\ eclass_builder\ editor.py", line 1083, in
UploadPage
self.UploadFile s(ftpfiles)
File "F:\oss\eclass\ eclass_builder\ editor.py", line 921, in
UploadFiles
ftp.UploadFiles ()
File "F:\oss\eclass\ eclass_builder\ editor.py", line 1908, in
UploadFiles
self.mysocket = self.host.trans fercmd('STOR ' + dir + myitem)
File "C:\PYTHON23\li b\ftplib.py", line 345, in transfercmd
return self.ntransferc md(cmd, rest)[0]
File "C:\PYTHON23\li b\ftplib.py", line 336, in ntransfercmd
raise error_reply, resp
ftplib.error_r eply: 200 PORT command successful.


I suspect the problem is in the bit marked with *. You are somehow sending
out a new FTP command before the previous was finished. The 226 belonged to
the transfer command but was eaten by the TYPE command, leaving a dangling
response to the TYPE command. Are you perhaps not waiting for the retrbinary
method to finish before sending another? Remember, there is more for
retrbinary to read after it has called the callback for the last time so you
must wait for it to finish.

Eddie
Jul 18 '05 #2
Kevin Ollivier <ke****@tulane. edu> wrote in message news:<ti******* *************** **********@4ax. com>...
The first file uploads just fine, but on the second file I'm
consistently seeing a weird problem where the response to the PORT
command (sent by self.makeport() ) comes *after* the STOR command is
sent.


Kevin, when you make a socket connection to the server, are you used
blocking or non-blocking? A blocking connection won't proceed until
it gets a response, while the non-blocking will - and perhaps your
problem lies there. your 2nd command gets a response before the first
one comes back.

Does indeed your problem only happen at the beginning, or can it
happen anywhere in your list of files?

S
Jul 18 '05 #3
On 19 Mar 2004 06:24:13 -0800, st*****@midwint er.ca (Stewart
Midwinter) wrote:
Kevin Ollivier <ke****@tulane. edu> wrote in message news:<ti******* *************** **********@4ax. com>...
The first file uploads just fine, but on the second file I'm
consistently seeing a weird problem where the response to the PORT
command (sent by self.makeport() ) comes *after* the STOR command is
sent.
Kevin, when you make a socket connection to the server, are you used
blocking or non-blocking? A blocking connection won't proceed until
it gets a response, while the non-blocking will - and perhaps your
problem lies there. your 2nd command gets a response before the first
one comes back.


I am using whatever method ftplib uses by default, in other words, I
do not explicitly set the socket as blocking or non-blocking.

After reading your reply (and the other I received), I tried
explicitly calling setblocking(1) on both the FTP socket (ftp.sock)
and the socket that is returned when I call transfercmd. However, the
PORT call's response still comes after the STOR command. (As far as I
could tell, setting blocking mode seemed to do nothing.)
Does indeed your problem only happen at the beginning, or can it
happen anywhere in your list of files?


It does always happen at the beginning, even when uploading to
different servers. But since I cannot get it to upload more than the
first file, I do not know if it would happen at other points in the
upload.

Thanks for your help!

Kevin
Jul 18 '05 #4
OK, I finally figured out how to fix my problems with the FTP commands
being issued in the wrong order - after I've finished uploading the
file, I have to call ftplib.voidresp ().

Is it possible to get this added as a note to the docs for
ftplib.transfer cmd()? IIUC, you must always call ftp.voidresp() after
uploading a file using transfercmd(), and if that's the case, then I
think it'd be helpful to add a note about it in the ftplib docs so
that the next person to come along and try something like this doesn't
run into the same problem.

Thanks,

Kevin

On Thu, 18 Mar 2004 23:17:16 -0800, Kevin Ollivier <ke****@tulane. edu>
wrote:
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("ST OR " +
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 None, then move on to the next file. I'm using
active FTP to upload.

The first file uploads just fine, but on the second file I'm
consistently seeing a weird problem where the response to the PORT
command (sent by self.makeport() ) comes *after* the STOR command is
sent. The order in which the commands are sent doesn't seem to differ,
only the order in which the FTP server responds differs. This causes
the transfercmd() call to see an 'error' because the repsonse to the
PORT command is a 200, but it expects a response in the 100s. I've
posted the actual FTP debug calls below.

I can resolve the problem by continually re-logging into the server,
but I'd like to avoid doing that if possible. I've tried setting the
file mode to binary as well as ASCII with the same results.

Any clues on what I may be going wrong? Has anyone seen anything like
this before? I couldn't find anything while googling... TIA for any
help!

Kevin

#uploading first file...
*cmd* u'CWD /newlook/tutorial/'
*put* u'CWD /newlook/tutorial/\r\n'
*get* '250 CWD command successful.\r\n '
*resp* '250 CWD command successful.'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '200 Type set to I.\r\n'
*resp* '200 Type set to I.'
item = /newlook/tutorial/pub/working_with_th emes.htm
*cmd* 'PORT 192,168,1,103,1 3,230'
*put* 'PORT 192,168,1,103,1 3,230\r\n'
*get* '200 PORT command successful.\r\n '
*resp* '200 PORT command successful.'
*cmd* u'STOR /newlook/tutorial/pub/working_with_th emes.htm'
*put* u'STOR /newlook/tutorial/pub/working_with_th emes.htm\r\n'
*get* '150 Opening BINARY mode data connection for
/newlook/tutorial/pub/working_with_th emes.htm.\r\n'
*resp* '150 Opening BINARY mode data connection for
/newlook/tutorial/pub/working_with_th emes.htm.'
*cmd* 'TYPE I'
*put* 'TYPE I\r\n'
*get* '226 Transfer complete.\r\n'
*resp* '226 Transfer complete.'

#uploading second file...
item = /newlook/tutorial/pub/Changing_Page_P roperties_1.htm
*cmd* 'PORT 192,168,1,103,1 3,231'
*put* 'PORT 192,168,1,103,1 3,231\r\n'
*get* '200 Type set to I.\r\n'
*resp* '200 Type set to I.'
*cmd* u'STOR /newlook/tutorial/pub/Changing_Page_P roperties_1.htm '
*put* u'STOR /newlook/tutorial/pub/Changing_Page_P roperties_1.htm \r\n'
*get* '200 PORT command successful.\r\n '
*resp* '200 PORT command successful.'
Traceback (most recent call last):
File "F:\oss\eclass\ eclass_builder\ editor.py", line 1083, in
UploadPage
self.UploadFile s(ftpfiles)
File "F:\oss\eclass\ eclass_builder\ editor.py", line 921, in
UploadFiles
ftp.UploadFiles ()
File "F:\oss\eclass\ eclass_builder\ editor.py", line 1908, in
UploadFiles
self.mysocket = self.host.trans fercmd('STOR ' + dir + myitem)
File "C:\PYTHON23\li b\ftplib.py", line 345, in transfercmd
return self.ntransferc md(cmd, rest)[0]
File "C:\PYTHON23\li b\ftplib.py", line 336, in ntransfercmd
raise error_reply, resp
ftplib.error_r eply: 200 PORT command successful.


Jul 18 '05 #5
Kevin Ollivier <ke****@tulane. edu> writes:
OK, I finally figured out how to fix my problems with the FTP commands
being issued in the wrong order - after I've finished uploading the
file, I have to call ftplib.voidresp (). Is it possible to get this added as a note to the docs for
ftplib.transfe rcmd()? IIUC, you must always call ftp.voidresp() after
uploading a file using transfercmd(), and if that's the case, then I
think it'd be helpful to add a note about it in the ftplib docs so
that the next person to come along and try something like this doesn't
run into the same problem.


It's more complicated than that. You have to be aware that FTP commands
generate responses, sometimes multiple responses but I think that's so rare
you can ignore it. Most of the ftplib commands hide this, when I replied to
the first post, I could see that the problem was probably that you weren't
eating your responses, unfortunately I didn't read your message carefully
enough to notice you were calling transfercmd directly (tsk tsk) and hence my
explanation was crap (sorry). In general you will often need to know what the
response actually is, however neither of the response gathering methods is
exposed, which is probably worth remedying.

Which brings me to the observation in that in such cases it's often best just
to look at the source. I had a similar problem when trying to turn an FTP
call into a generator but soon noticed all those calls to voidresp.

However it's probably worth trying to get the documentation augmented to
remind users that transfercmd may need to handle responses and to request that
at least getresp be added as a public interface. I think there's a
special mail address for such requests but I'm too lazy^H^H^H^Hbus y to look it
up just now.

Eddie
Jul 18 '05 #6

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

Similar topics

3
2396
by: Mariela | last post by:
I am trying to run the following C# code: ---------------------------------------- String uriString = "http://10.1.1.100/images/"; WebClient myWebClient = new WebClient(); string fileName = "C:\\agoodfriend.jpg"; byte responseArray = myWebClient.UploadFile (uriString,"POST",fileName); ---------------------------------------- But I get the following error:
2
1048
by: Dany | last post by:
Hi I was wondering wether it was possible to upload files to a server using only ASP (without external components, such as "AspSmartUpload") and te code might look like Thank you -Dany
3
1450
by: darin dimitrov | last post by:
Hello, I have the following Html form: <form name="submitForProcess" action="http://localhost/xml/process.aspx" method="post" enctype="multipart/form-data"> <input type="text" name="customerId" value="5" /><br /> <input type="text" name="customerName" value="Johnson" /><br />
0
1622
by: pbd22 | last post by:
Hi. I am having a really tough time here and would appreciate some help. i am using an iFrame to pass a url string of files to upload to server. on the client i have created a multiple upload javascript using the below link: http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/
1
1966
JAMBAI
by: JAMBAI | last post by:
How to upload files in ASP.NET along with Virus scan simillar to mail attachments in yahoo,gmail or any other mailing system. Thanks Jambai
3
5808
by: mollymalone | last post by:
im trying to upload a file using php and apache and i get a blank screen when i submit the file. the php and apache are configured correct as i can open a test php file and as the file i want to upload is small there shouldnt be any problem with the size.can anybody help me?
1
4580
by: tregewitz | last post by:
I am uploading a zip file using an HttpWebRequest and a PUT operation to Sharepoint (2003) from a Windows Form application. When I upload the same file using the Sharepoint Portal Web UI itself, the file uploads in 1/3 the time. If I copy the file over the network using Windows Explorer, it also copies in about 1/3 of the time. I don't understand why it is taking so much longer transferring it in this way. I've tried several...
0
2767
by: LoriFranklin | last post by:
I'm a bit of a newbie here. I've learned a lot from reading the posts you all have here. I need some help uploading files using an asp form. I am using some code that I found from Jacob at asp101.com. http://www.asp101.com/articles/jacob/scriptupload.asp My three files are: Syllabus.htm <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
1
1580
by: govind161986 | last post by:
When i execute the below mentioned code in .NET 1.1 i get the following error message "A socket operation was attempted to an unreachable host" but when i execute the same code in .NET 2.0 it executes successfully. main_sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); main_ipEndPoint = new IPEndPoint(Dns.GetHostByName(server).AddressList, port); try { ...
0
8969
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
9342
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...
1
9272
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9211
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...
0
8218
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6056
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3286
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
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2195
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.