0

I have the following code:

import ftplib
import easygui

# log in
session = ftplib.FTP(host, username, password)

# upload thumbnail
print('Select your thumnbail')
thumbnail = easygui.fileopenbox('', 'Select your thumbnail')
thumbnailsplit = thumbnail.split('\\')
thumbnailname = thumbnailsplit[-1]
ftplib.FTP.cwd(dirname='/thumbnails')
file = open(thumbnail, 'rb')
session.storbinary(f'STOR {thumbnailname}', file)

# close session
file.close()
session.quit()

According to the docs this should change the directory to 'thumbnails' in my FTP server but I get this error instead:

Traceback (most recent call last):
  File "MovieUpload.py", line 13, in <module>
    ftplib.FTP.cwd(dirname='/thumbnails')
TypeError: cwd() missing 1 required positional argument: 'self'

The docs state to use it like this:

FTP.cwd(pathname)

What am I doing wrong?

jamjam46
  • 75
  • 9

2 Answers2

1

You should use the instance of ftplib.FTP that you created on login for your ftp operations.

import ftplib
session = ftplib.FTP(host, username, password)
session.cwd('/thumbnails')
rhymefororange
  • 341
  • 1
  • 7
0

You should use full path, like this /home/user/folder/subfolder

Andrii
  • 74
  • 6