mar10 / pyftpsync

Synchronize directories using FTP(S), SFTP, or file system access.
https://pyftpsync.readthedocs.io
MIT License
117 stars 25 forks source link

cannot sync on Windows server #12

Closed wiwengweng closed 8 years ago

wiwengweng commented 8 years ago

Hi, I come to your project and tried to sync a directory on win10 with a win10 IIS FTP server. But unfortunately I got errors: here is my demo:

from ftpsync.targets import FsTarget
from ftpsync.ftp_target import FtpTarget
from ftpsync.synchronizers import BiDirSynchronizer

local = FsTarget("c:\\win10disableimgpath\\")
user ="administrator"
passwd = "123456"
remote = FtpTarget("/controller", "10.1.101.195", username=user, password=passwd)
opts = {"resolve": "skip", "verbose": 1, "dry_run" : False}
s = BiDirSynchronizer(local, remote, opts)
s.run()

on the ftp://10.1.101.195/controller/ directory, I have a simple txt file in it. like this. and the lock file is created yet.

.pyftpsync-lock.json 50 B 16/9/26 4:11:00 pysync.txt 32 B 16/9/26 4:02:00

and here is the error:

C:\Python27\python.exe C:/center/test/sk2.py Synchronize c:\win10disableimgpath Traceback (most recent call last): with ftp:10.1.101.195/controller File "C:/center/test/sk2.py", line 25, in s.run() File "C:\Python27\lib\site-packages\ftpsync\synchronizers.py", line 128, in run res = self._sync_dir() File "C:\Python27\lib\site-packages\ftpsync\synchronizers.py", line 375, in _sync_dir remote_entries = self.remote.get_dir() File "C:\Python27\lib\site-packages\ftpsync\ftp_target.py", line 270, in get_dir self.ftp.retrlines("MLSD", _addline) File "C:\Python27\lib\ftplib.py", line 437, in retrlines conn = self.transfercmd(cmd) File "C:\Python27\lib\ftplib.py", line 376, in transfercmd return self.ntransfercmd(cmd, rest)[0] File "C:\Python27\lib\ftplib.py", line 339, in ntransfercmd resp = self.sendcmd(cmd) File "C:\Python27\lib\ftplib.py", line 249, in sendcmd return self.getresp() File "C:\Python27\lib\ftplib.py", line 224, in getresp raise error_perm, resp ftplib.error_perm: 500 Command not understood.

can you please help with this?

wiwengweng commented 8 years ago

I try all the 3 Synchronizer, but with no luck. I am not sure if wrong code. Can u help look into it? Thanks.

mar10 commented 8 years ago

It seems that your FTP server does not support the MLSD command, This is required by PyFtpSync. (You could try that with a command line FTP client or talk to your admin)

File "C:\Python27\lib\site-packages\ftpsync\ftp_target.py", line 270, in get_dir
self.ftp.retrlines("MLSD", _addline)
...
ftplib.error_perm: 500 Command not understood.
wiwengweng commented 8 years ago

Thanks mar10. I recognize MLSD, but cannot find any post mentioned 'MLSD and Windows Internet Information Server'. Or do you have any FTP server recommanded? I am just starting this new job, so changing a server is not a big deal.

wiwengweng commented 8 years ago

Now that I found out I can type 'help' to show if the FTP server support mlsd command. However I tried IIS and Filezila, both not.

mar10 commented 8 years ago

I don't know much about FTP servers, but since there are troubleshooting tips for MLSD on the web, I assume this command is often available (e.g. https://support.managed.com/kb/a1915/ftp-client-will-not-connect-to-microsoft-ftp-server.aspx). May be it has to be enabled in some way or is not advertised using the FEAT command. You could try MLSD . directly for example

wiwengweng commented 8 years ago

Hi, mar10. I made a mistake because filezila support MLSD, also MLST, when I start filezila server, and I see the command in this way:

(000032)16/09/29 14:36:55 - (not logged in) (127.0.0.1)> PASS ******
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)> 230 Logged on
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)> SYST
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)> 215 UNIX emulated by FileZilla
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)> FEAT
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)> 211-Features:
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)>  MDTM
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)>  REST STREAM
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)>  SIZE
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)>  MLST type*;size*;modify*;
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)>  MLSD
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)>  UTF8
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)>  CLNT
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)>  MFMT
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)>  EPSV
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)>  EPRT
(000032)16/09/29 14:36:55 - wenyunlong (127.0.0.1)> 211 End

so I suppose it running fine.

as I again run the sample above, I got 550 permission denied then. like this

C:\Python27\python.exe C:/center/test/sk2.py
Synchronize C:\win10disableimgpath
Could not write lock file: 550 Permission denied
                with ftp:10.1.101.195/
Traceback (most recent call last):
  File "C:/center/test/sk2.py", line 123, in <module>
    s.run()
  File "C:\Python27\lib\site-packages\ftpsync\synchronizers.py", line 128, in run
    res = self._sync_dir()
  File "C:\Python27\lib\site-packages\ftpsync\synchronizers.py", line 408, in _sync_dir
    self.sync_newer_local_file(local_file, remote_file)
  File "C:\Python27\lib\site-packages\ftpsync\synchronizers.py", line 633, in sync_newer_local_file
    self._copy_file(self.local, self.remote, local_file)
  File "C:\Python27\lib\site-packages\ftpsync\synchronizers.py", line 172, in _copy_file
    dest.write_file(file_entry.name, fp_src, callback=__block_written)
  File "C:\Python27\lib\site-packages\ftpsync\ftp_target.py", line 328, in write_file
    self.ftp.storbinary("STOR %s" % name, fp_src, blocksize, callback)
  File "C:\Python27\lib\ftplib.py", line 471, in storbinary
    conn = self.transfercmd(cmd, rest)
  File "C:\Python27\lib\ftplib.py", line 376, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "C:\Python27\lib\ftplib.py", line 339, in ntransfercmd
    resp = self.sendcmd(cmd)
  File "C:\Python27\lib\ftplib.py", line 249, in sendcmd
    return self.getresp()
  File "C:\Python27\lib\ftplib.py", line 224, in getresp
    raise error_perm, resp
ftplib.error_perm: 550 Permission denied
wiwengweng commented 8 years ago

I use FTPHost(just another ftp lib), this two folder work without permission problem. Can you figure it out? Thanks

mar10 commented 8 years ago

In your first comment you said that the lock file was created, but in the latest error, we see that this was not possible:

Synchronize C:\win10disableimgpath
                with ftp:10.1.101.195/
Could not write lock file: 550 Permission denied

Did you change the target root path to / since then? Do you have write access on ftp:10.1.101.195/?

The 2nd error message is clearly a permission error generated by the server

You could try to run this with verbose: 3, or set a breakpoint at ftp_target.py, line 328 to see whats going on.

khubab commented 1 year ago

It is simple. I am using FileZilla server and I have defined directory under groups instead of user. Though, both works the same and lead to the error Could not write lock file: 550 Permission denied. Then I moved to the shared folder option and given the permissions, create, append, delete for the directory and it starts working