473,473 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Recursive FTP script problem

2 New Member
Hi,

I'm working on a system that recurses through a given directory, ftp-ing all the contents up to our FTP server. I've got the recursion bit working fine, but whenever I try to upload a file I get the following error:

ftplib.error_perm: 550 C:\testxml\asdas.txt: The filename, directory name or volume label syntax is incorrect.

My code is as follows:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. import ftplib
  3. import os
  4.  
  5. def upload(ftp, file):
  6.     ext = os.path.splitext(file)[1]
  7.     if ext in (".txt", ".htm", ".html"):
  8.         ftp.storlines("STOR " + file, open(file))
  9.     else:
  10.         ftp.storbinary("STOR " + file, open(file, "rb"), 1024)  
  11.  
  12. def walktree(ftp, top = ".", depthfirst = True):
  13.     import os, stat, types
  14.     names = os.listdir(top)
  15.  
  16.     for name in names:
  17.         try:
  18.             st = os.lstat(os.path.join(top, name))
  19.             print(os.path.join(top, name))
  20.             upload(ftp, os.path.join(top, name))
  21.         except os.error:
  22.             continue
  23.         if stat.S_ISDIR(st.st_mode):
  24.              walktree (ftp, os.path.join(top, name), depthfirst)
  25.  
  26. ftp = ftplib.FTP("xxxxxxx")
  27. ftp.login("xxxxxxxx", "xxxxxxxx")
  28.  
  29. if __name__ == '__main__':
  30.     if len(sys.argv) == 2:
  31.         top = sys.argv[1]
  32.     else: top = '.'
  33.     walktree(ftp, top, True)
  34.  
The string which represents the filesystem address that is passed into the upload function appears to be correct, of the form C:\TestXml\asdas.txt.

Any ideas? I've run out of things to try.

Thanks
Mar 26 '07 #1
5 7986
bartonc
6,596 Recognized Expert Expert
Hi,

I'm working on a system that recurses through a given directory, ftp-ing all the contents up to our FTP server. I've got the recursion bit working fine, but whenever I try to upload a file I get the following error:

ftplib.error_perm: 550 C:\testxml\asdas.txt: The filename, directory name or volume label syntax is incorrect.

My code is as follows:
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. import ftplib
  3. import os
  4.  
  5. def upload(ftp, file):
  6.     ext = os.path.splitext(file)[1]
  7.     if ext in (".txt", ".htm", ".html"):
  8.         ftp.storlines("STOR " + file, open(file))
  9.     else:
  10.         ftp.storbinary("STOR " + file, open(file, "rb"), 1024)  
  11.  
  12. def walktree(ftp, top = ".", depthfirst = True):
  13.     import os, stat, types
  14.     names = os.listdir(top)
  15.  
  16.     for name in names:
  17.         try:
  18.             st = os.lstat(os.path.join(top, name))
  19.             print(os.path.join(top, name))
  20.             upload(ftp, os.path.join(top, name))
  21.         except os.error:
  22.             continue
  23.         if stat.S_ISDIR(st.st_mode):
  24.              walktree (ftp, os.path.join(top, name), depthfirst)
  25.  
  26. ftp = ftplib.FTP("xxxxxxx")
  27. ftp.login("xxxxxxxx", "xxxxxxxx")
  28.  
  29. if __name__ == '__main__':
  30.     if len(sys.argv) == 2:
  31.         top = sys.argv[1]
  32.     else: top = '.'
  33.     walktree(ftp, top, True)
  34.  
The string which represents the filesystem address that is passed into the upload function appears to be correct, of the form C:\TestXml\asdas.txt.

Any ideas? I've run out of things to try.

Thanks
Not sure if FTP likes or dislikes "\". Try using raw strings. ie r"C:\TestXml\asdas.txt" or escaping the back slash "C:\\TestXml\\asdas.txt" by hand at first. Then use the os module to format the name correctly for you.

I've added CODE tags to your post. Please read "REPLY GUIDELINES" in order to learn how to do this. Thanks for joining the Python Forum on TheScripts.com.
Mar 26 '07 #2
AlunDavies
2 New Member
Not sure if FTP likes or dislikes "\". Try using raw strings. ie r"C:\TestXml\asdas.txt" or escaping the back slash "C:\\TestXml\\asdas.txt" by hand at first. Then use the os module to format the name correctly for you.

I've added CODE tags to your post. Please read "REPLY GUIDELINES" in order to learn how to do this. Thanks for joining the Python Forum on TheScripts.com.
Hi bartonc,

Thanks for the reply. I've tried both your solutions (using raw strings and manually escaping the backslash) and neither seemed to make any difference. After looking into the problem a bit more I'm wondering if it might be something to do with changing the ftp's working directory? The problem is whenever I use the ftp.cwd() function I get the same error as above. Anybody got any ideas?
Mar 26 '07 #3
bartonc
6,596 Recognized Expert Expert
Hi bartonc,

Thanks for the reply. I've tried both your solutions (using raw strings and manually escaping the backslash) and neither seemed to make any difference. After looking into the problem a bit more I'm wondering if it might be something to do with changing the ftp's working directory? The problem is whenever I use the ftp.cwd() function I get the same error as above. Anybody got any ideas?
If it were me, I'd have to run a "commercial" (free) FTP on some site, look at the log and figure out from there what the FTP directory name format is.
Mar 26 '07 #4
ghostdog74
511 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. .....
  2. ftp = ftplib.FTP("xxxxxxx")
  3. ftp.login("xxxxxxxx", "xxxxxxxx")
  4. ftp.set_debuglevel(5)  
  5. .....
  6.  
you can add a debug statement and see what other information you can see. vary the level number to your needs.
Mar 27 '07 #5
harshalbhakta
1 New Member
hi AlunDavies,
try using "/" instead of "\" in the path.
this will definitely solve your problem. Let me know if it doesn't work.

-
thanks,
harshal bhakta
May 22 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Michael Foord | last post by:
I've been using the excellent XMLObject and have unfortunately come up against what *looks* to me like a bug - although it's very possible that the problem is mine !! I want to use XML object...
6
by: Phil | last post by:
Hello I'm trying to display all DIV tags of a document : Example : + <DIV id="1"> - <DIV id="1-1"></DIV> </DIV> + <DIV id="2"> - <DIV id="2-1"></DIV>
8
by: Ryan Stewart | last post by:
Putting the following code in a page seems to make it go into an infinite loop unless you give it a very simple node to work with. Either that or it's very very slow. I'm somewhat new to this,...
13
by: nobody | last post by:
Hello all, I've searched just about everything and although I can see that other people are having problems, but theirs don't seem to relate, so in a last ditch attempt, my posting! Script...
7
by: Jon Slaughter | last post by:
#pragma once #include <vector> class empty_class { }; template <int _I, int _J, class _element, class _property> class RDES_T {
4
by: Nicolas Vigier | last post by:
Hello, I have in my python script a function that look like this : def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42): if type(arg1) is ListType: for a in arg1: my_function(a, arg2,...
3
by: Robertico | last post by:
I'am new to php and have a question about a recursive file search. I'd like to do a recursive search for jpg-files and add the filenames (full path) to a mysql database. I appreciate any help ! ...
5
by: Gordon | last post by:
I'm trying to remove a directory and all its contents from within a script. I wrote a recursive function to take care of it, but when I run it I get random "Directory not empty" error messages. ...
2
by: wgarner | last post by:
I am trying to implement a two-dimensional recursive formula, g(x,y). It is sort of like multiplication. g(x,y) = 0 if either x or y is 0. g(1, y) = y and g(x, 1) = x. Those are the base...
6
KevinADC
by: KevinADC | last post by:
This snippet of code provides several examples of programming techniques that can be applied to most programs. using hashes to create unique results static variable recursive function...
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
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...
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...
1
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...
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.