3

I have some file remotely :

___________
[somevar]
Test: 2
___________

And i want to change var "Test" to 3 for example so i will have :

___________
[somevar]
Test: 3
___________

I'm using this function to upload file

    ftp = ftplib.FTP('')
    ftp.connect(HOSTNAME,PORT)
    ftp.login(FTP_NAME,FTP_PASS)
    file = open(PATH + FILENAME, 'rb')
    ftp.storbinary('STOR '+FILENAME, file)
    file.close() 
    ftp.quit()

I know I can download the file, change it localy then upload it again But i'm searching for a remotely solution

Do you think this could be done ?


Can i do this via IOString :

Here is my code, unfortunately this doesn't work :(


    # Writing to a buffer
    ChangeVar = StringIO("[Somevar] \nTest: 3")
    ftp = ftplib.FTP('')
    ftp.connect(HOSTNAME,FTP_PORT)
    ftp.login(FTP_NAME,FTP_PASS)

    ftp.storbinary('STOR '+Myvarfile, switchVar)

    #Disconnect
    ftp.quit()

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
BlackRoot
  • 33
  • 5

1 Answers1

0

You can't change the file remotely without RETR + STOR though you can edit it in the memory without saving if it is small.

wRAR
  • 25,009
  • 4
  • 84
  • 97
  • How can i do that without writing to disk ? – BlackRoot Jul 13 '11 at 18:44
  • The second argument of ftp.retrbinary accepts a function, which is called for each chunk of data that's downloaded. You can do this: `my_list = []; ftp.retrbinary('RETR '+FILENAME, my_list.append)`. – MRAB Jul 13 '11 at 19:30