i have this code in python2.7 for upload photos.zip file on the server via ftp.
import ftplib
session = ftplib.FTP('server.address.com','USERNAME','PASSWORD')
file = open('c:\archived\photos.zip','rb') # file to send
session.storbinary('STOR photos.zip', file) # send the file
file.close() # close file and FTP
session.quit()
but i have this error :
raceback (most recent call last):
File "a.py", line 24, in <module>
file = open('c:\archived\photos.zip','rb')
IOError: [Errno 22] invalid mode ('rb') or filename: 'c:\archived\photos.zip'
also I used this solution :
file = open(os.path.join('c:/','archived','photos.zip'),'rb')
but I get this error :
Traceback (most recent call last):
File "s.py", line 28, in <module>
session.storbinary('s.zip', file)
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 479, in storbinary
conn = self.transfercmd(cmd, rest)
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 378, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 341, in ntransfercmd
resp = self.sendcmd(cmd)
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 251, in sendcmd
return self.getresp()
File "C:\Users\0xuser\Anaconda2\lib\ftplib.py", line 226, in getresp
raise error_perm, resp
ftplib.error_perm: 500 Unknown command.
Try using forward slashes :
file = open('c:/archived/photos.zip','rb') # file to send
Related
What am I missing, when using the package rarfile when simply extracting a password protected rar file? The same exception is raised, when the password is byte-encoded. Right and wrong passwords raise this exception.
from rarfile import RarFile
with RarFile("testfile_rar.rar", 'r') as rf:
rf.extractall(pwd='Pass?')
throws:
Traceback (most recent call last):
File "/home/x/PythonProjects/rarPW/unpack_rar.py", line 4, in <module>
rf.extractall(pwd='Pass?')
File "/home/x/PythonProjects/rarPW/venv/lib/python3.10/site-packages/rarfile.py", line 847, in extractall
dst = self._extract_one(inf, path, pwd, not inf.is_dir())
File "/home/x/PythonProjects/rarPW/venv/lib/python3.10/site-packages/rarfile.py", line 912, in _extract_one
return self._make_file(info, dstfn, pwd, set_attrs)
File "/home/x/PythonProjects/rarPW/venv/lib/python3.10/site-packages/rarfile.py", line 925, in _make_file
with self.open(info, "r", pwd) as src:
File "/home/x/PythonProjects/rarPW/venv/lib/python3.10/site-packages/rarfile.py", line 783, in open
return self._file_parser.open(inf, pwd)
File "/home/x/PythonProjects/rarPW/venv/lib/python3.10/site-packages/rarfile.py", line 1241, in open
return self._open_unrar(self._rarfile, inf, pwd)
File "/home/x/PythonProjects/rarPW/venv/lib/python3.10/site-packages/rarfile.py", line 1294, in _open_unrar
cmd = setup.open_cmdline(pwd, rarfile, fn)
File "/home/x/PythonProjects/rarPW/venv/lib/python3.10/site-packages/rarfile.py", line 3235, in open_cmdline
cmdline = self.get_cmdline("open_cmd", pwd)
File "/home/x/PythonProjects/rarPW/venv/lib/python3.10/site-packages/rarfile.py", line 3247, in get_cmdline
self.add_password_arg(cmdline, pwd)
File "/home/x/PythonProjects/rarPW/venv/lib/python3.10/site-packages/rarfile.py", line 3265, in add_password_arg
cmdline.extend(args)
TypeError: 'NoneType' object is not iterable
I am trying to run the remote manager example code from the multiprocessing documentation in pypy3 but I get an error connecting the client.
Traceback (most recent call last):
File "C:/temp/testpypy/mp_client.py", line 7, in <module>
m.connect()
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\managers.py", line 455, in connect
conn = Client(self._address, authkey=self._authkey)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 493, in Client
answer_challenge(c, authkey)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 732, in answer_challenge
message = connection.recv_bytes(256) # reject large message
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 216, in recv_bytes
buf = self._recv_bytes(maxlength)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 407, in _recv_bytes
buf = self._recv(4)
File "C:\Python\pypy3-v6.0.0-win32\lib-python\3\multiprocessing\connection.py", line 386, in _recv
buf.write(chunk)
TypeError: 'str' does not support the buffer interface
if I try to connect to it from a CPython interpreter (which is my ultimate goal) I get the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\managers.py", line 455, in connect
conn = Client(self._address, authkey=self._authkey)
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 493, in Client
answer_challenge(c, authkey)
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 737, in answer_challenge
response = connection.recv_bytes(256) # reject large message
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 218, in recv_bytes
self._bad_message_length()
File "c:\Python\3.5.4.2\WinPython\python-3.5.4.amd64\lib\multiprocessing\connection.py", line 151, in _bad_message_length
raise OSError("bad message length")
OSError: bad message length
Turns out to be a bug in PyPy3.
Here is the fixed ticket:
https://bitbucket.org/pypy/pypy/issues/2841/remote-multprocessing-issue#comment-45861347
Hi I'm using pyftpsync in order to upload new images (downloaded every day) in a online store skipping the existing ones.
From the author site I'm using this code (with my personal data of course):
from ftpsync.targets import FsTarget
from ftpsync.ftp_target import FtpTarget
from ftpsync.synchronizers import UploadSynchronizer
local = FsTarget("~/temp")
user ="joe"
passwd = "secret"
remote = FtpTarget("/temp", "example.com", username=user, password=passwd)
opts= {"force": False, "delete_unmatched": True, "verbose": 3, "dry_run" : False}
s = UploadSynchronizer(local, remote, opts,tls=True)
s.run()
This work for me correctly only if I delete the tls option, otherwise I obtain this error while connecting to my server:
Traceback (most recent call last):
File "sync.py", line 25, in <module>
s.run()
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/synchronizers.py", line 139, in run
res = self._sync_dir()
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/synchronizers.py", line 416, in _sync_dir
remote_entries = self.remote.get_dir()
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/ftp_target.py", line 310, in get_dir
self.ftp.retrlines("MLSD", _addline)
File "/usr/lib/python3.4/ftplib.py", line 466, in retrlines
resp = self.sendcmd('TYPE A')
File "/usr/lib/python3.4/ftplib.py", line 272, in sendcmd
return self.getresp()
File "/usr/lib/python3.4/ftplib.py", line 235, in getresp
resp = self.getmultiline()
File "/usr/lib/python3.4/ftplib.py", line 221, in getmultiline
line = self.getline()
File "/usr/lib/python3.4/ftplib.py", line 209, in getline
raise EOFError
EOFError
Could not remove lock file: Underlying socket connection gone (_ssl.c:1570)
Exception ignored in: <bound method FtpTarget.__del__ of <ftpsync.ftp_target.FtpTarget object at 0x7fe397ae7710>>
Traceback (most recent call last):
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/targets.py", line 70, in __del__
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/ftp_target.py", line 153, in close
File "/media/luca/1E9C3E629C3E349D/luca/Documenti/attività/Cataloghi2/ftpsync/ftp_target.py", line 187, in _unlock
File "/usr/lib/python3.4/ftplib.py", line 613, in delete
File "/usr/lib/python3.4/ftplib.py", line 271, in sendcmd
File "/usr/lib/python3.4/ftplib.py", line 198, in putcmd
File "/usr/lib/python3.4/ftplib.py", line 193, in putline
File "/usr/lib/python3.4/ssl.py", line 720, in sendall
File "/usr/lib/python3.4/ssl.py", line 681, in send
ssl.SSLError: Underlying socket connection gone (_ssl.c:1570)
It's obviously a problem related to the encryption, but I don't know how to fix it.
I am trying to upload a file using ftplib and python. I continue getting this error and don't know why...help?
Traceback (most recent call last):
File "C:\Users\212392169\Desktop\ftp_trial.py", line 15, in <module>
ftp.storbinary("STOR samplee.bin", f)
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 Can't open file "samplee.bin"
Source Code:
from ftplib import FTP
ftp = FTP(host)
ftp.login(host,pw)
ftp.cwd("/dflts")
f = open('samplee.bin', 'rb')
ftp.storbinary("STOR samplee.bin", f)
f.close()
ftp.quit()
That error means that you don't have permission to upload the file.
ftp.login(host, pw)
^^^^
Is the host really what you meant?
I want to get a list of folders in a ftp directory, but I'm getting the following error:
directory list of folder /myfolder
Traceback (most recent call last):
File "./run.py", line 12, in <module>
folderList = connection.nlst()
File "/usr/local/lib/python2.7/ftplib.py", line 506, in nlst
self.retrlines(cmd, files.append)
File "/usr/local/lib/python2.7/ftplib.py", line 429, in retrlines
conn = self.transfercmd(cmd)
File "/usr/local/lib/python2.7/ftplib.py", line 368, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "/usr/local/lib/python2.7/ftplib.py", line 331, in ntransfercmd
resp = self.sendcmd(cmd)
File "/usr/local/lib/python2.7/ftplib.py", line 244, in sendcmd
return self.getresp()
File "/usr/local/lib/python2.7/ftplib.py", line 219, in getresp
raise error_perm, resp
ftplib.error_perm: 502 Command not implemented
And here's the sorcecode:
#!/usr/bin/python
import ftplib
connection = ftplib.FTP("10.0.99.11")
#connection.set_pasv(False)
connection.login(user='abc', passwd='1234')
rootDir = "/myfolder"
connection.cwd(rootDir)
print "directory list of folder ",rootDir
#connection.retrlines('LIST')
folderList = connection.nlst()
for folderEntry in folderList:
print folderEntry
print "end of list"
# close connection
connection.quit()
Thanks for your help and any information or idea you have.