0

I just wanted to ask how do you append a file when using the FTP library in python. I understand how to read/upload a file using FTP but how would i append to one. I was looking online and it montioned using a function called 'APPE' but im not sure how this works. This is what i have so far.

ftp= FTP('some ip',a username','password')
ftp.cwd('directory/direct/dir')
ftp.storbinary('STOR atestfile.txt', open ('/home/pi/aFolder/afile1.txt', 'rb'))
ftp.close()

I would like to append the 'atestfile.txt' file. Thanks ~Neamus

Neamus
  • 198
  • 1
  • 3
  • 16

1 Answers1

1
    import ftplib
    ftp = ftplib.FTP('some ip')
    ftp.login ('username','password')
    fin = open ('foo.txt', 'r')
    ftp.storbinary ('APPE foo2.txt', fin, 1)
    ftp.close()

Please make sure the file on the server is writable.

Chukwuemeka Inya
  • 2,575
  • 1
  • 17
  • 23