1 # -*- coding: utf-8; -*-
4 # Part of ‘dput’, a Debian package upload toolkit.
6 # Copyright © 2015 Ben Finney <ben+python@benfinney.id.au>
7 # Copyright © 2008–2013 Y Giridhar Appaji Nag <appaji@debian.org>
8 # Copyright © 2007 Thomas Viehmann <tv@beamnet.de>
10 # This is free software: you may copy, modify, and/or distribute this work
11 # under the terms of the GNU General Public License as published by the
12 # Free Software Foundation; version 2 of that license or any later version.
13 # No warranty expressed or implied. See the file ‘LICENSE.GPL-2’ for details.
15 """ Implementation for FTP upload method. """
17 from __future__
import absolute_import
24 from ..helper
import dputhelper
28 fqdn
, login
, incoming
, files_to_upload
, debug
, ftp_mode
,
30 """ Upload the files via FTP.
32 (Could need a bit more error-checking.)
37 ftp_connection
= ftplib
.FTP()
38 ftp_connection
.connect(fqdn
, port
)
40 sys
.stdout
.write("D: FTP-Connection to host: %s\n" % fqdn
)
41 except ftplib
.all_errors
as e
:
43 "Connection failed, aborting. Check your network\n"
46 prompt
= login
+ "@" + fqdn
+ " password: "
47 if login
== 'anonymous':
48 password
= 'dput@packages.debian.org'
50 password
= getpass
.getpass(prompt
)
52 ftp_connection
.login(login
, password
)
53 except ftplib
.error_perm
:
54 sys
.stdout
.write("Wrong Password\n")
57 sys
.stdout
.write("Server closed the connection\n")
59 ftp_connection
.set_pasv(ftp_mode
== 1)
61 ftp_connection
.cwd(incoming
)
62 except ftplib
.error_perm
as e
:
63 if e
.args
and e
.args
[0][:3] == '550':
64 sys
.stdout
.write("Directory to upload to does not exist.\n")
69 sys
.stdout
.write("D: Directory to upload to: %s\n" % incoming
)
70 for afile
in files_to_upload
:
71 path_to_package
, package_name
= os
.path
.split(afile
)
74 sys
.stdout
.write("D: Uploading File: %s\n" % afile
)
77 size
= os
.stat(afile
).st_size
82 "D: Determining size of file '%s' failed\n"
86 f
= dputhelper
.FileWithProgress(
90 sys
.stdout
.write(" Uploading %s: " % package_name
)
92 ftp_connection
.storbinary(
93 'STOR ' + package_name
,
96 sys
.stdout
.write("done.\n")
98 except ftplib
.all_errors
as e
:
99 sys
.stdout
.write("%s\n" % e
)
101 isinstance(e
, ftplib
.Error
)
102 and e
.args
and e
.args
[0][:3] == '553'):
104 "Leaving existing %s on the server and continuing\n"
107 "NOTE: This existing file may have been"
108 " previously uploaded partially.\n"
109 "For official Debian upload queues,"
110 " the dcut(1) utility can be\n"
111 "used to remove this file, and after"
112 " an acknowledgement mail is\n"
113 "received in response to dcut,"
114 " the upload can be re-initiated.\n")
117 isinstance(e
, ftplib
.Error
)
118 and e
.args
and e
.args
[0][:1] == '5'):
120 "Note: This error might indicate a problem with"
121 " your passive_ftp setting.\n"
122 "Please consult dput.cf(5) for details on"
123 " this configuration option.\n")
126 "D: Should exit silently now, but"
127 " will throw exception for debug.\n")
131 ftp_connection
.quit()
132 except Exception as e
:
135 "D: Exception %s while attempting to quit ftp session.\n"
136 "D: Throwing an exception for debugging purposes.\n" % e
)
144 # vim: fileencoding=utf-8 filetype=python :