Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Fix to fileclient for ftp connections #55052

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion salt/fileclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,10 @@ def s3_opt(key, default=None):
if url_data.scheme == 'ftp':
try:
ftp = ftplib.FTP()
ftp.connect(url_data.hostname, url_data.port)
ftp_port = url_data.port
if not ftp_port:
ftp_port = 21
ftp.connect(url_data.hostname, ftp_port)
ftp.login(url_data.username, url_data.password)
remote_file_path = url_data.path.lstrip('/')
with salt.utils.files.fopen(dest, 'wb') as fp_:
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/modules/test_cp.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,21 @@ def test_get_url_file_no_dest(self):
self.assertIn('KNIGHT: They\'re nervous, sire.', ret)
self.assertNotIn('bacon', ret)

@with_tempfile()
def test_get_url_ftp(self, tgt):
'''
cp.get_url with https:// source given
'''
self.run_function(
'cp.get_url',
[
'ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/12.0-RELEASE/MANIFEST',
tgt,
])
with salt.utils.files.fopen(tgt, 'r') as instructions:
data = salt.utils.stringutils.to_unicode(instructions.read())
self.assertIn('Base system', data)

# cp.get_file_str tests

def test_get_file_str_salt(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/states/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def test_managed_contents_with_contents_newline(self):
flag.
'''
contents = 'test_managed_contents_with_newline_one'
name = os.path.join(TMP, 'foo')
name = os.path.join(RUNTIME_VARS.TMP, 'foo')

# Create a file named foo with contents as above but with a \n at EOF
self.run_state('file.managed', name=name, contents=contents,
Expand All @@ -594,7 +594,7 @@ def test_managed_contents_with_contents_newline_false(self):
flag.
'''
contents = 'test_managed_contents_with_newline_one'
name = os.path.join(TMP, 'bar')
name = os.path.join(RUNTIME_VARS.TMP, 'bar')

# Create a file named foo with contents as above but with a \n at EOF
self.run_state('file.managed', name=name, contents=contents,
Expand All @@ -610,7 +610,7 @@ def test_managed_multiline_contents_with_contents_newline(self):
'''
contents = ('this is a cookie{}this is another cookie'.
format(os.linesep))
name = os.path.join(TMP, 'bar')
name = os.path.join(RUNTIME_VARS.TMP, 'bar')

# Create a file named foo with contents as above but with a \n at EOF
self.run_state('file.managed', name=name, contents=contents,
Expand All @@ -626,7 +626,7 @@ def test_managed_multiline_contents_with_contents_newline_false(self):
'''
contents = ('this is a cookie{}this is another cookie'.
format(os.linesep))
name = os.path.join(TMP, 'bar')
name = os.path.join(RUNTIME_VARS.TMP, 'bar')

# Create a file named foo with contents as above but with a \n at EOF
self.run_state('file.managed', name=name, contents=contents,
Expand Down