Ticket #28 (closed enhancement: wontfix)
Additional parameters for files
| Reported by: | ftputiluser | Owned by: | schwa |
|---|---|---|---|
| Priority: | minor | Milestone: | never |
| Component: | Library | Version: | 2.2.3 |
| Keywords: | MVS, file, arguments | Cc: |
Description
For writing binary files on MVS I needed to send some additional commands to the ftp server. The following codes shows an example:
file = ftputil.FTPHost(host, user, password).file("/"+name, "wb",
addcmds=("SITE BLKSIZE=0",
"SITE RECFMT=FB",
"SITE LRECL=%d" % length ))
Btw. this example shows a workaround for track # 26 by adding a "/" to the filename.
I applied the following patches to achieve this behaviour:
--- ftputil.py
+++ ../ftputil-2.2.3/ftputil.py
@@ -191,7 +191,7 @@
# be explicit
return None
- def file(self, path, mode='r', **args):
+ def file(self, path, mode='r'):
"""
Return an open file(-like) object which is associated with
this `FTPHost` object.
@@ -220,7 +220,7 @@
# raise an `IOError`, not an `OSError`
raise ftp_error.FTPIOError("remote directory '%s' doesn't exist "
"or has insufficient access rights" % effective_dir)
- host._file._open(effective_file, mode, **args)
+ host._file._open(effective_file, mode)
if 'w' in mode:
self.stat_cache.invalidate(effective_path)
return host._file
--- ftp_file.py
+++ ../ftputil-2.2.3/ftp_file.py
@@ -87,15 +87,8 @@
# the file is closed yet
self.closed = True
- def _open(self, path, mode, **args):
- """ Open the remote file with given path name and mode
- and possibly additional arguments.
-
- Possible keys for args:
- addcmds List of additional ftp-commands to send
- before the STOR/RETR command (e.g. to set
- file information on mvs)
- """
+ def _open(self, path, mode):
+ """Open the remote file with given path name and mode."""
# check mode
if 'a' in mode:
raise ftp_error.FTPIOError("append mode not supported")
@@ -108,8 +101,6 @@
transfer_type = ('A', 'I')[self._bin_mode]
command = 'TYPE %s' % transfer_type
ftp_error._try_with_ioerror(self._session.voidcmd, command)
- for command in args.get("addcmds", []) :
- ftp_error._try_with_ioerror(self._session.voidcmd, command)
# make transfer command
command_type = ('STOR', 'RETR')[self._read_mode]
command = '%s %s' % (command_type, path)
Hopefully, you like this patch and incorporate it into ftputil.
Regards, Axel
Change History
Note: See
TracTickets for help on using
tickets.
