0

I've received following error when trying to execute script to copy specific file from remote server to jumphost and then to my local computer.

Traceback (most recent call last):
  File "list_files.py", line 34, in <module>
    stdin, stdout, stderr = p.exec_command('sshpass -p %s scp -r hostname:/directory/' + list[file_number] + ' ' + '/desired_directory' % (password))
TypeError: not all arguments converted during string formatting
stdin, stdout, stdeer = p.exec_command('sshpass -p %s ssh hostname ls /directory/' % (password))
for line in stdout:
    if line:
        list.append(line)
i = 0
for x in list:
    print(str(i) + '. ' + x)
    i+=1

file_number = input("Type log file number you would like to get: ")

stdin, stdout, stderr = p.exec_command('sshpass -p %s scp -r hostname:/directory/' + list[file_number] + ' ' + '/desired_directory/downloaded_file_name' % (password))

I've already tried change syntax to the ${0} instead of %s but it didn't help. I assume problem is in list[file_number] not in %s.

1 Answer 1

3
'sshpass -p %s scp -r hostname:/directory/' + list[file_number] + ' ' + '/desired_directory/downloaded_file_name' % (password)

Because of operator precedence, this fragment means the formatting only applies to '/desired_directory/downloaded_file_name'. ;)

To fix it, either put all string concatenation in parentheses or move % formatting to the first element only:

('sshpass -p %s scp -r hostname:/directory/' + list[file_number] + ' ' + '/desired_directory/downloaded_file_name') % (password)```
'sshpass -p %s scp -r hostname:/directory/' % (password) + list[file_number] + ' ' + '/desired_directory/downloaded_file_name'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.