Forum Archive

Create .txt in a FTP folder?

philg

Hello. I managed to connect to my ftp and create a new directory with ftp.mkd(folderName). However, I want to create a txt file within this folder and write in it with another string. In quick steps:

  1. Create a blank .txt file (in a FTP folder, that's the important part)
  2. Add text to the .txt file.

How it gets done?

MAYBE, I fixed by creating a local file, there we go:

article = 'This is my whole article.'

open('article.txt', 'w').write(article)
ftp.storlines('STOR ' + path/to/folder/article.txt, open('article.txt','r'))
os.remove('article.txt')

I believe this generates a local text file in my device, so I thought about using os.remove to delete it afterwards, does it work as I could expect?

ccc

It all looks right to me. Is it doing all the stuff that you had hoped it would?

I used the indispensable Shellista to verify that: 1) the local file is getting created, 2) has the right content, and 3) is getting properly deleted.
(http://omz-software.com/pythonista/forums/discussion/74/advanced-shell-shellista)

philg

It does.

Thank you for Shellista. And for confirming that my local file is being deleted.